secara lebih baik. JAVA sendiri menyediakan dua graphical library, yaitu :
- AWT (Abstract Windows Toolkit)
- Swing
- Swt
)
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; }
0 comments:
Posting Komentar