Welcome to Abdul Malik Ikhsan's Blog

Awt event

Posted in Tutorial Java by samsonasik on April 5, 2007

import javax.swing.*;
import java.awt.event.*;
class satu
{
public static void main(String args[])
{
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame=new JFrame();
frame.setTitle(“satu”);
frame.setBounds(50,50,450,200);

JLabel l=new JLabel(“Nama anda: “);
l.setBounds(20,50,70,30);
frame.getContentPane().add(l);
frame.getContentPane().setLayout(null);

final JTextField t=new JTextField();
t.setText(“”);
t.setBounds(100,50,200,30);
frame.getContentPane().add(t);

JLabel l2=new JLabel(“Alamat : “);
l2.setBounds(20,90,70,30);
frame.getContentPane().add(l2);
frame.getContentPane().setLayout(null);

final JTextField t2=new JTextField();
t2.setText(“”);
t2.setBounds(100,90,200,30);
frame.getContentPane().add(t2);

JButton b=new JButton(“OK”);
b.setBounds(300,90,100,30);
frame.getContentPane().add(b);

b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null,”Halo ” +t.getText()+”\nAlamat anda di “+t2.getText()); //ditulis dalam satu baris
System.exit(0);
}});
frame.getContentPane().setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

}
}//Berikut tampilan programmnya

javaswingupload1.jpg
javaswing2upload.jpg

Advertisements

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: