SamaLoa - Java GUI Part 3 - Tampilan3
Hasil Tampilan3 ketika dijalankan |
Langsung aja codingnya :
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Tampilan3{
public Tampilan3(){
JFrame frame = new JFrame();
final JTextField txtNim = new JTextField(30);
final JTextField txtNama = new JTextField(30);
JButton btnNim = new JButton("Nim");
JButton btnNama = new JButton("Nama");
JButton btnKosong = new JButton("Kosongkan");
btnNim.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
txtNim.setText("12.11.5980");
}
});
btnNama.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
txtNama.setText("M.Nur Fadillah");
}
});
btnKosong.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
txtNama.setText("");
txtNim.setText("");
}
});
Container contentPane = frame.getContentPane();
contentPane.setLayout(new FlowLayout());
contentPane.add(txtNim);
contentPane.add(btnNim);
contentPane.add(txtNama);
contentPane.add(btnNama);
contentPane.add(btnKosong);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args){
new Tampilan3();
}
}
0 comments:
Post a Comment