/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Soal3;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author admin
*/
public class Panel extends JPanel implements ActionListener {
private JLabel name, paswd;
private JTextField nm, pw;
private JButton ok;
public Panel() {
setLayout(new GridLayout(2, 1));
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(2, 2));
name = new JLabel();
name.setText("Input your User Name :");
paswd = new JLabel();
paswd.setText("Input your Password :");
nm = new JTextField();
nm.setColumns(22);
nm.addActionListener(this);
pw = new JTextField();
pw.setColumns(22);
pw.addActionListener(this);
p1.add(name);
p1.add(nm);
p1.add(paswd);
p1.add(pw);
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());
ok = new JButton("OK");
ok.addActionListener(this);
p2.add(ok);
this.add(p1);
this.add(p2);
}
public void actionPerformed(ActionEvent e) {
String button;
button = e.getActionCommand();
if (button.equals("OK")) {
if ((nm.getText().equals("root")) && (pw.getText().equals("123456"))) {
JOptionPane.showMessageDialog(this, "ok");
} else {
JOptionPane.showMessageDialog(this, "Salah");
}
}
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Soal3;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author admin
*/
public class Panel extends JPanel implements ActionListener {
private JLabel name, paswd;
private JTextField nm, pw;
private JButton ok;
public Panel() {
setLayout(new GridLayout(2, 1));
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(2, 2));
name = new JLabel();
name.setText("Input your User Name :");
paswd = new JLabel();
paswd.setText("Input your Password :");
nm = new JTextField();
nm.setColumns(22);
nm.addActionListener(this);
pw = new JTextField();
pw.setColumns(22);
pw.addActionListener(this);
p1.add(name);
p1.add(nm);
p1.add(paswd);
p1.add(pw);
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());
ok = new JButton("OK");
ok.addActionListener(this);
p2.add(ok);
this.add(p1);
this.add(p2);
}
public void actionPerformed(ActionEvent e) {
String button;
button = e.getActionCommand();
if (button.equals("OK")) {
if ((nm.getText().equals("root")) && (pw.getText().equals("123456"))) {
JOptionPane.showMessageDialog(this, "ok");
} else {
JOptionPane.showMessageDialog(this, "Salah");
}
}
}
}
Tidak ada komentar:
Posting Komentar