* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package testsoal_3;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
/**
*
* @author admin
*/
public class Soal3 extends JInternalFrame implements ActionListener {
JPanel p1, p2, p3;
JLabel l1, l2, l3;
JTextField t1, t2;
JButton but1;
public Soal3() {
JPanel P = new JPanel();
setSize(400, 400);
P.setLayout(new GridLayout(2, 1));
setContentPane(P);
p1 = new JPanel();
p1.setBackground(Color.WHITE);
p1.setLayout(new GridLayout(2, 2));
l1 = new JLabel("input your user name");
p1.add(l1);
t1 = new JTextField();
t1.setColumns(10);
p1.add(t1);
l2 = new JLabel("input your password");
p1.add(l2);
t2 = new JTextField();
t2.setColumns(10);
l3 = new JLabel();
p1.add(t2);
P.add(p1);
p2 = new JPanel();
p2.setBackground(Color.WHITE);
but1 = new JButton("Ok");
p2.add(but1);
P.add(p2);
but1.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
String s = e.getActionCommand();
if (s.equals("Ok")) {
String nama = t1.getText();
String pass = t2.getText();
if (nama.equals("root") && pass.equals("admin")) {
JOptionPane.showMessageDialog(null, "password ok");
} else {
JOptionPane.showMessageDialog(null, "salah");
// throw new Exception("salah");
}
}
}
}
kelas lain
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package testsoal_3;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
/**
*
* @author admin
*/
public class Soal_3 extends JFrame {
JMenuBar menuBar;
JMenu file, utama2;
JMenuItem a1, a2, a3;
JLabel l1;
JTextField t1;
JButton but1;
public Soal_3() {
super("Password");
menuBar = new JMenuBar();
file = new JMenu("FILE");
menuBar.add(file);
a1 = new JMenuItem("Menu Password");
file.add(a1);
a2 = new JMenuItem("Exit");
file.add(a2);
setDefaultCloseOperation(EXIT_ON_CLOSE);
//
this.setJMenuBar(menuBar);
// JPanel P = new JPanel();
// setSize(400, 400);
// P.setLayout(new GridLayout(2, 1));
// setContentPane(P);
// JPanel p1 = new JPanel();
// p1.setBackground(Color.WHITE);
// p1.setLayout(new GridLayout(2, 2));
// l1 = new JLabel("input your user name");
// p1.add(l1);
// t1 = new JTextField();
// t1.setColumns(10);
// p1.add(t1);
// JLabel l2 = new JLabel("input your password");
// p1.add(l2);
// t1 = new JTextField();
// t1.setColumns(10);
// p1.add(t1);
// P.add(p1);
// JPanel p2 = new JPanel();
// p2.setBackground(Color.WHITE);
// but1 = new JButton("Ok");
// p2.add(but1);
// P.add(p2);
a1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// throw new UnsupportedOperationException("Not supported yet.");
a1Action();
}
});
}
private void a1Action (){
Soal3 frames = new Soal3();
frames.setVisible(true);
this.add(frames);
}
}
kelas main
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package testsoal_3;
import java.awt.*;
import javax.swing.*;
/**
*
* @author admin
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Soal_3 a= new Soal_3();
a.setSize(600, 300);
a.setVisible(true);
}
}
http://www.ziddu.com/download/17897490/NetBeansProjects.zip.html
Tidak ada komentar:
Posting Komentar