RSS

contoh form insert data dan event tombol

04 Jun

package andre;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class bless extends JFrame{
JLabel jLabel1=new JLabel(“Id”);
JLabel jLabel2=new JLabel(“Nama”);
JLabel jLabel3=new JLabel(“Alamat”);
JLabel jLabel4=new JLabel(“E-mail”);

JTextField jTextField1=new JTextField(15);
JTextField jTextField2=new JTextField(15);
JTextField jTextField3=new JTextField(15);
JTextField jTextField4=new JTextField(15);

JButton jButton1=new JButton(“Inser”);
JButton jButton2=new JButton(“Search”);
JButton jButton3=new JButton(“Update”);
JButton jButton4=new JButton(“Delete”);
JButton jButton5=new JButton(“Clear”);
JButton jButton6=new JButton(“Close”);

JPanel jPanelLabel=new JPanel(new GridLayout(4,1));
JPanel jPanelTextField=new JPanel(new GridLayout(4,1));
JPanel jPanelButton=new JPanel(new GridLayout(3,3));
JPanel jPanelSeting=new JPanel(new BorderLayout());

Font font=new Font(“Arial”,Font.ITALIC,20);
public bless(){
label_komponen();
}
public void label_komponen(){
text_field_komponen();
jPanelLabel.add(jLabel1);
jLabel1.setFont(font);
jPanelLabel.add(jLabel2);
jLabel2.setFont(font);
jPanelLabel.add(jLabel3);
jLabel3.setFont(font);
jPanelLabel.add(jLabel4);
jLabel4.setFont(font);
button_komponen();
}
public void text_field_komponen(){
jPanelTextField.add(jTextField1);
jTextField1.setFont(font);
jPanelTextField.add(jTextField2);
jTextField2.setFont(font);
jPanelTextField.add(jTextField3);
jTextField3.setFont(font);
jPanelTextField.add(jTextField4);
jTextField4.setFont(font);
panel_seting1();
}
public void button_komponen(){
jPanelButton.add(jButton1);
jButton1.setFont(font);
jPanelButton.add(jButton2);
jButton2.setFont(font);
jPanelButton.add(jButton3);
jButton3.setFont(font);
jPanelButton.add(jButton4);
jButton4.setFont(font);
jPanelButton.add(jButton5);
jButton5.setFont(font);
jPanelButton.add(jButton6);
jButton6.setFont(font);
panel_seting2();

}
public void panel_seting1(){
jPanelSeting.add(jPanelLabel,BorderLayout.WEST);
jPanelSeting.add(jPanelTextField,BorderLayout.EAST);
jPanelSeting.add(jPanelButton,BorderLayout.SOUTH);
set_border_komponen();
}
public void set_border_komponen(){
jPanelLabel.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
jPanelTextField.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
jPanelButton.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
}
public void panel_seting2(){
setContentPane(jPanelSeting);
pack();
setLocation(300,20);
setVisible(true);
action_listener();
}
public void action_listener(){
jButton1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,”Action Insert”);
clear();
}
});
jButton2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,”Action Search”);
}
});
jButton3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,”Action Update”);
clear();
}
});
jButton4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,”Action Delete”);
clear();
}
});
jButton5.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,”Action Clear”);
clear();
}
});
jButton6.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,”Action Close”);
}
});
}
public void clear(){
jTextField1.setText(“”);
jTextField2.setText(“”);
jTextField3.setText(“”);
jTextField4.setText(“”);
}
public static void main(String[]bangke_tonk_zampah){
try{
// lookandfeel lafW=new lookandfeel();
UIManager.setLookAndFeel(“com.sun.java.swing.plaf.windows.WindowsLookAndFeel”);
new bless();
}catch(Exception ex){
}
}
}

class lookandfeel{
bless b=new bless();
public void lookandfeel(){
try{
UIManager.setLookAndFeel(“com.sun.java.swing.plaf.windows.WindowsLookAndFeel”);
}catch(Exception ex){
}
}
}

 
Leave a comment

Posted by on June 4, 2011 in about me

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: