tesajadeh

Leo Saga

Oct 19th, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.60 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package alpro1b_3;
  7.  
  8. import static java.awt.image.ImageObserver.WIDTH;
  9. import javax.swing.JOptionPane;
  10.  
  11. /**
  12. *
  13. * @author Febryanto Budiman
  14. */
  15. public class Pengulangan_Kata extends javax.swing.JDialog {
  16.  
  17. /**
  18. * Creates new form Pengulangan_Kata
  19. */
  20. public Pengulangan_Kata(java.awt.Frame parent, boolean modal) {
  21. super(parent, modal);
  22. initComponents();
  23. }
  24.  
  25. /**
  26. * This method is called from within the constructor to initialize the form.
  27. * WARNING: Do NOT modify this code. The content of this method is always
  28. * regenerated by the Form Editor.
  29. */
  30. @SuppressWarnings("unchecked")
  31. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  32. private void initComponents() {
  33.  
  34. jLabel1 = new javax.swing.JLabel();
  35. eKATA = new javax.swing.JTextField();
  36. jLabel2 = new javax.swing.JLabel();
  37. eJUMLAH = new javax.swing.JTextField();
  38. bProses = new javax.swing.JButton();
  39. bReset = new javax.swing.JButton();
  40. bKeluar = new javax.swing.JButton();
  41.  
  42. setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  43. setTitle("Pengulangan Kata");
  44.  
  45. jLabel1.setText("Masukkan karakter yang ingin dicetak berulang : ");
  46.  
  47. jLabel2.setText("Masukkan berapa kali harus dicetak ulang : ");
  48.  
  49. bProses.setText("Proses");
  50. bProses.addActionListener(new java.awt.event.ActionListener() {
  51. public void actionPerformed(java.awt.event.ActionEvent evt) {
  52. bProsesActionPerformed(evt);
  53. }
  54. });
  55.  
  56. bReset.setText("Reset");
  57. bReset.addActionListener(new java.awt.event.ActionListener() {
  58. public void actionPerformed(java.awt.event.ActionEvent evt) {
  59. bResetActionPerformed(evt);
  60. }
  61. });
  62.  
  63. bKeluar.setText("Keluar");
  64. bKeluar.addActionListener(new java.awt.event.ActionListener() {
  65. public void actionPerformed(java.awt.event.ActionEvent evt) {
  66. bKeluarActionPerformed(evt);
  67. }
  68. });
  69.  
  70. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  71. getContentPane().setLayout(layout);
  72. layout.setHorizontalGroup(
  73. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  74. .addGroup(layout.createSequentialGroup()
  75. .addGap(36, 36, 36)
  76. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  77. .addGroup(layout.createSequentialGroup()
  78. .addComponent(bProses, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
  79. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  80. .addComponent(bReset, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
  81. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  82. .addComponent(bKeluar, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
  83. .addGroup(layout.createSequentialGroup()
  84. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  85. .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  86. .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  87. .addGap(18, 18, 18)
  88. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  89. .addComponent(eKATA, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
  90. .addComponent(eJUMLAH, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE))))
  91. .addContainerGap(45, Short.MAX_VALUE))
  92. );
  93. layout.setVerticalGroup(
  94. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  95. .addGroup(layout.createSequentialGroup()
  96. .addGap(36, 36, 36)
  97. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  98. .addComponent(jLabel1)
  99. .addComponent(eKATA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  100. .addGap(18, 18, 18)
  101. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  102. .addComponent(jLabel2)
  103. .addComponent(eJUMLAH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  104. .addGap(21, 21, 21)
  105. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  106. .addComponent(bReset, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  107. .addGroup(layout.createSequentialGroup()
  108. .addComponent(bProses, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
  109. .addGap(0, 0, Short.MAX_VALUE))
  110. .addComponent(bKeluar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  111. .addContainerGap())
  112. );
  113.  
  114. pack();
  115. }// </editor-fold>
  116.  
  117. private void bProsesActionPerformed(java.awt.event.ActionEvent evt) {
  118. // TODO add your handling code here:
  119. try{
  120. String strkata ="";
  121. String strjumlah ="";
  122. String strtitle = "";
  123. int i = 1;
  124. int i_jumlah =0;
  125. strkata= eKATA.getText();
  126. strjumlah = eJUMLAH.getText();
  127.  
  128.  
  129. if (strkata.trim().equals("")){
  130. String msg = "Karakter tidak boleh kosong!";
  131. JOptionPane.showMessageDialog(rootPane, msg, "Warning!", WIDTH);
  132. eKATA.requestFocus();
  133. }
  134. else if (strjumlah.trim().equals("")) {
  135. String msg = "Jumlah tidak boleh kosong!";
  136. JOptionPane.showMessageDialog(rootPane, msg, "Warning!", WIDTH);
  137. eJUMLAH.requestFocus();
  138. }
  139. else{
  140. i_jumlah = Integer.parseInt(strjumlah);
  141.  
  142. while (i <= i_jumlah){
  143. strtitle = "" + i;
  144. String msg = strkata;
  145. JOptionPane.showMessageDialog(rootPane, msg, "Pengulangan ke-" + strtitle, WIDTH);
  146. i++;
  147. }
  148. }
  149.  
  150. }catch(Exception e){
  151. // Tangkap error & Munculkan
  152. e.printStackTrace();
  153. String msg = " Ada Error, sbb :"+e.getMessage();
  154. JOptionPane.showMessageDialog(rootPane, msg, "Warning!", WIDTH);
  155.  
  156. }
  157. }
  158.  
  159. private void bResetActionPerformed(java.awt.event.ActionEvent evt) {
  160. // TODO add your handling code here:
  161. eKATA.setText("");
  162. eJUMLAH.setText("");
  163. eKATA.requestFocus();
  164. }
  165.  
  166. private void bKeluarActionPerformed(java.awt.event.ActionEvent evt) {
  167. // TODO add your handling code here:
  168. dispose();
  169. }
  170.  
  171. /**
  172. * @param args the command line arguments
  173. */
  174. public static void main(String args[]) {
  175. /* Set the Nimbus look and feel */
  176. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  177. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  178. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  179. */
  180. try {
  181. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  182. if ("Nimbus".equals(info.getName())) {
  183. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  184. break;
  185. }
  186. }
  187. } catch (ClassNotFoundException ex) {
  188. java.util.logging.Logger.getLogger(Pengulangan_Kata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  189. } catch (InstantiationException ex) {
  190. java.util.logging.Logger.getLogger(Pengulangan_Kata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  191. } catch (IllegalAccessException ex) {
  192. java.util.logging.Logger.getLogger(Pengulangan_Kata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  193. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  194. java.util.logging.Logger.getLogger(Pengulangan_Kata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  195. }
  196. //</editor-fold>
  197.  
  198. /* Create and display the dialog */
  199. java.awt.EventQueue.invokeLater(new Runnable() {
  200. public void run() {
  201. Pengulangan_Kata dialog = new Pengulangan_Kata(new javax.swing.JFrame(), true);
  202. dialog.addWindowListener(new java.awt.event.WindowAdapter() {
  203. @Override
  204. public void windowClosing(java.awt.event.WindowEvent e) {
  205. System.exit(0);
  206. }
  207. });
  208. dialog.setVisible(true);
  209. }
  210. });
  211. }
  212.  
  213. // Variables declaration - do not modify
  214. private javax.swing.JButton bKeluar;
  215. private javax.swing.JButton bProses;
  216. private javax.swing.JButton bReset;
  217. private javax.swing.JTextField eJUMLAH;
  218. private javax.swing.JTextField eKATA;
  219. private javax.swing.JLabel jLabel1;
  220. private javax.swing.JLabel jLabel2;
  221. // End of variables declaration
  222. }
Advertisement
Add Comment
Please, Sign In to add comment