SamaLoa - Java GUI Part 1 - Tampilan1
Hasil Tampilan1 ketika dijalankan |
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Tampilan1{
public Tampilan1(){
JFrame frame = new JFrame();
JLabel label = new JLabel("Pesan : ");
final JTextField txtPesan = new JTextField(30);
JButton btnTampil = new JButton("Tampilkan");
JButton btnKosong = new JButton("Kosongkan");
txtPesan.setText("Ketik Disini");
btnTampil.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
JOptionPane.showMessageDialog(null, txtPesan.getText());
}
});
btnKosong.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
txtPesan.setText("");
}
});
Container contentPane = frame.getContentPane();
contentPane.setLayout(new FlowLayout());
contentPane.add(label);
contentPane.add(txtPesan);
contentPane.add(btnTampil);
contentPane.add(btnKosong);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args){
new Tampilan1();
}
}
0 comments:
Post a Comment