Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package alpro1b_3;
- import static java.awt.image.ImageObserver.WIDTH;
- import javax.swing.JOptionPane;
- /**
- *
- * @author Febryanto Budiman
- */
- public class Pengulangan_Kata extends javax.swing.JDialog {
- /**
- * Creates new form Pengulangan_Kata
- */
- public Pengulangan_Kata(java.awt.Frame parent, boolean modal) {
- super(parent, modal);
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- eKATA = new javax.swing.JTextField();
- jLabel2 = new javax.swing.JLabel();
- eJUMLAH = new javax.swing.JTextField();
- bProses = new javax.swing.JButton();
- bReset = new javax.swing.JButton();
- bKeluar = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- setTitle("Pengulangan Kata");
- jLabel1.setText("Masukkan karakter yang ingin dicetak berulang : ");
- jLabel2.setText("Masukkan berapa kali harus dicetak ulang : ");
- bProses.setText("Proses");
- bProses.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- bProsesActionPerformed(evt);
- }
- });
- bReset.setText("Reset");
- bReset.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- bResetActionPerformed(evt);
- }
- });
- bKeluar.setText("Keluar");
- bKeluar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- bKeluarActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(36, 36, 36)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addGroup(layout.createSequentialGroup()
- .addComponent(bProses, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(bReset, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(bKeluar, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(eKATA, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(eJUMLAH, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE))))
- .addContainerGap(45, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(36, 36, 36)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(eKATA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(eJUMLAH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(21, 21, 21)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(bReset, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(layout.createSequentialGroup()
- .addComponent(bProses, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(0, 0, Short.MAX_VALUE))
- .addComponent(bKeluar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addContainerGap())
- );
- pack();
- }// </editor-fold>
- private void bProsesActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- try{
- String strkata ="";
- String strjumlah ="";
- String strtitle = "";
- int i = 1;
- int i_jumlah =0;
- strkata= eKATA.getText();
- strjumlah = eJUMLAH.getText();
- if (strkata.trim().equals("")){
- String msg = "Karakter tidak boleh kosong!";
- JOptionPane.showMessageDialog(rootPane, msg, "Warning!", WIDTH);
- eKATA.requestFocus();
- }
- else if (strjumlah.trim().equals("")) {
- String msg = "Jumlah tidak boleh kosong!";
- JOptionPane.showMessageDialog(rootPane, msg, "Warning!", WIDTH);
- eJUMLAH.requestFocus();
- }
- else{
- i_jumlah = Integer.parseInt(strjumlah);
- while (i <= i_jumlah){
- strtitle = "" + i;
- String msg = strkata;
- JOptionPane.showMessageDialog(rootPane, msg, "Pengulangan ke-" + strtitle, WIDTH);
- i++;
- }
- }
- }catch(Exception e){
- // Tangkap error & Munculkan
- e.printStackTrace();
- String msg = " Ada Error, sbb :"+e.getMessage();
- JOptionPane.showMessageDialog(rootPane, msg, "Warning!", WIDTH);
- }
- }
- private void bResetActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- eKATA.setText("");
- eJUMLAH.setText("");
- eKATA.requestFocus();
- }
- private void bKeluarActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- dispose();
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(Pengulangan_Kata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Pengulangan_Kata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Pengulangan_Kata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Pengulangan_Kata.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the dialog */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- Pengulangan_Kata dialog = new Pengulangan_Kata(new javax.swing.JFrame(), true);
- dialog.addWindowListener(new java.awt.event.WindowAdapter() {
- @Override
- public void windowClosing(java.awt.event.WindowEvent e) {
- System.exit(0);
- }
- });
- dialog.setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton bKeluar;
- private javax.swing.JButton bProses;
- private javax.swing.JButton bReset;
- private javax.swing.JTextField eJUMLAH;
- private javax.swing.JTextField eKATA;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment