AWT (Abstract Window Toolkit) – SUN Microsystem -> Oracle Product

19.20 viia 0 Comments


AWT (Abstract Window Toolkit) ini adalah GUI Toolkit pertama pada bahasa pemrograman Java, sayang-nya AWT ini sangat-sangat kekurangan komponen yang biasa digunakan untuk membangun sebuah aplikasi desktop secara lengkap (komponen tabel saja tidak ada ) Terlepas dari kurang-nya komponen GUI yang terdapat pada AWT (Abstract Window Toolkit), aplikasi yang dibangun menggunakan AWT (Abstract Window Toolkit) akan tampak seperti aplikasi native. Maksudnya yaitu, jika aplikasi yang dibangun menggunakan AWT (Abstract Window Toolkit) ini dijalankan pada Sistem Operasi Windows. Maka aplikasi ini akan terlihat seperti aplikasi Windows pada umum-nya, dan begitu juga jika dijalankan pada Sistem Operasi Mac ataupun GNU/Linux. Kenapa ini bisa terjadi, karena AWT (Abstract Window Toolkit) ini benar-benar memanggil native subrutin untuk menggambar setiap komponen-nya ke layar. Tidak percaya ? Mari kita lihat tampilan ke 2 screenshot dibawah ini:











Tampilan Aplikasi Berbasis AWT Di Ms Windows

sedangkan source-code yang digunakan pada tampilan form diatas ada di bawah ini :
public class SwingForm extends javax.swing.JFrame {       /** Creates new form SwingForm */     public SwingForm() {         initComponents();     }       @SuppressWarnings("unchecked")     //      private void initComponents() {         .....     }//        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                  // TODO add your handling code here:     }                                               private void resetLaf() {         SwingUtilities.updateComponentTreeUI(this);     }       private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {         try {             UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());             resetLaf();         } catch (ClassNotFoundException ex) {             Logger.getLogger(SwingForm.class.getName()).log(Level.SEVERE, null, ex);         } catch (InstantiationException ex) {             Logger.getLogger(SwingForm.class.getName()).log(Level.SEVERE, null, ex);         } catch (IllegalAccessException ex) {             Logger.getLogger(SwingForm.class.getName()).log(Level.SEVERE, null, ex);         } catch (UnsupportedLookAndFeelException ex) {             Logger.getLogger(SwingForm.class.getName()).log(Level.SEVERE, null, ex);         }     }       private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {         try {             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());             resetLaf();         } catch (ClassNotFoundException ex) {             Logger.getLogger(SwingForm.class.getName()).log(Level.SEVERE, null, ex);         } catch (InstantiationException ex) {             Logger.getLogger(SwingForm.class.getName()).log(Level.SEVERE, null, ex);         } catch (IllegalAccessException ex) {             Logger.getLogger(SwingForm.class.getName()).log(Level.SEVERE, null, ex);         } catch (UnsupportedLookAndFeelException ex) {             Logger.getLogger(SwingForm.class.getName()).log(Level.SEVERE, null, ex);         }     }       private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {         try {             UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");             resetLaf();         } catch (ClassNotFoundException ex) {             Logger.getLogger(SwingForm.class.getName()).log(Level.SEVERE, null, ex);         } catch (InstantiationException ex) {             Logger.getLogger(SwingForm.class.getName()).log(Level.SEVERE, null, ex);         } catch (IllegalAccessException ex) {             Logger.getLogger(SwingForm.class.getName()).log(Level.SEVERE, null, ex);         } catch (UnsupportedLookAndFeelException ex) {             Logger.getLogger(SwingForm.class.getName()).log(Level.SEVERE, null, ex);         }     }       private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {         try {             UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");             resetLaf();         } catch (ClassNotFoundException ex) {             Logger.getLogger(SwingForm.class.getName()).log(Level.SEVERE, null, ex);         } catch (InstantiationException ex) {             Logger.getLogger(SwingForm.class.getName()).log(Level.SEVERE, null, ex);         } catch (IllegalAccessException ex) {             Logger.getLogger(SwingForm.class.getName()).log(Level.SEVERE, null, ex);         } catch (UnsupportedLookAndFeelException ex) {             Logger.getLogger(SwingForm.class.getName()).log(Level.SEVERE, null, ex);         }     }       .....     ..... }



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
public class AwtFrame extends java.awt.Frame {
private java.awt.CheckboxGroup checkBoxGroup;

public AwtFrame() {
checkBoxGroup = new java.awt.CheckboxGroup();

initComponents();
}

private void initComponents() {
panel1 = new java.awt.Panel();
label1 = new java.awt.Label();
txtKdBarang = new java.awt.TextField();
label2 = new java.awt.Label();
txtNmBarang = new java.awt.TextField();
label3 = new java.awt.Label();
checkBoxEceran = new java.awt.Checkbox();
checkBoxPack = new java.awt.Checkbox();
txtArea = new java.awt.TextArea();
button1 = new java.awt.Button();
button2 = new java.awt.Button();
menuBar1 = new java.awt.MenuBar();
menu1 = new java.awt.Menu();
menuItem1 = new java.awt.MenuItem();
menu2 = new java.awt.Menu();

setMinimumSize(new java.awt.Dimension(500, 300));
setTitle("AWT Form Example");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});

label1.setText("Kode Barang");
label2.setText("Nama Barang");
label3.setText("Kategori");

checkBoxEceran.setCheckboxGroup(checkBoxGroup);
checkBoxEceran.setLabel("Eceran");
checkBoxEceran.setState(true);

checkBoxPack.setCheckboxGroup(checkBoxGroup);
checkBoxPack.setLabel("Pack");

button1.setLabel("Tambah");
button1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
button1ActionPerformed(evt);
}
});

button2.setLabel("Clear");
button2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
button2ActionPerformed(evt);
}
});

add(panel1, java.awt.BorderLayout.CENTER);
menu1.setLabel("File");
menuItem1.setLabel("Exit");
menuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuItem1ActionPerformed(evt);
}
});
menu1.add(menuItem1);
menuBar1.add(menu1);
menu2.setLabel("Edit");
menuBar1.add(menu2);
setMenuBar(menuBar1);
pack();
}// </editor-fold>

/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}

private void menuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
exitForm(new java.awt.event.WindowEvent(this, WIDTH));
}

private void clearField() {
txtKdBarang.setText("");
txtNmBarang.setText("");
}

private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
txtArea.append("\nKode Barang = " + txtKdBarang.getText());
txtArea.append("\nNama Barang = " + txtNmBarang.getText());
txtArea.append("\nKategori Barang = " + checkBoxGroup.getSelectedCheckbox().getLabel());
clearField();
txtKdBarang.requestFocusInWindow();
}

private void button2ActionPerformed(java.awt.event.ActionEvent evt) {
clearField();
txtArea.setText("");
}

// Variables declaration - do not modify
private java.awt.Button button1;
private java.awt.Button button2;
private java.awt.Checkbox checkBoxEceran;
private java.awt.Checkbox checkBoxPack;
private java.awt.Label label1;
private java.awt.Label label2;
private java.awt.Label label3;
private java.awt.Menu menu1;
private java.awt.Menu menu2;
private java.awt.MenuBar menuBar1;
private java.awt.MenuItem menuItem1;
private java.awt.Panel panel1;
private java.awt.TextArea txtArea;
private java.awt.TextField txtKdBarang;
private java.awt.TextField txtNmBarang;
}






diambil dari http://martinusadyh.web.id/2010/04/23/macam-macam-gui-tookit-pada-java/#more-575

0 komentar: