import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class jinianjun implements ActionListener {
JPanel p = new JPanel();
private JTextField t1,t2;
JButton button1,button2,button3,button4;
JPasswordField K1;
public jinianjun (JFrame f,JPanel p ){
f.add(p);
p.setLayout(null);
p.setBackground(Color.GRAY);
t1=new JTextField(20); t1.setBounds(200,60,100,25);
t2=new JTextField(20); t2.setBounds(200,120,100,25);
button1=new JButton("我的名字");button1.setBounds(100, 60, 100, 25);
button2=new JButton("我的密码");button2.setBounds(100, 120, 100, 25);
button3=new JButton("确定"); button3.setBounds(80, 200, 80, 25);button3.addActionListener(this);
button4=new JButton("取消"); button4.setBounds(240, 200, 80, 25);button4.addActionListener(this);
K1=new JPasswordField("qilaoshi");
p.add(t1);p.add(t2);p.add(button1);p.add(button2);p.add(button3);p.add(button4);
p.add(K1);
f.setVisible(true);
f.setBounds(400, 100, 400, 300);
f.validate();
}
public static void main(String[] args) {
new jinianjun(new JFrame("我的登录窗口"),new JPanel());
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() ==button1){
System.out.println("用户名:"+button1.getText());
System.out.println("密码:"+button2.getText());
if("wyjwsj".equals(button1.getText().trim())&&"12345".equals(button2.getText().trim())){
this.dispose();
new MainFrm("用户界面",button1.getText().trim(),button2.getText().trim());
}else {
JOptionPane.showMessageDialog(this, "用户名或密码不对!");
}
}else if(e.getSource()==button2){
System.exit(1);
}
}
private void dispose() {
}
class MainFrm extends JFrame{
private JLabel info;
public MainFrm(String s,String name,String password) {
super(s);
setBounds(400, 200, 500, 400);
setLayout(new FlowLayout());
info=new JLabel("登陆成功,用户名:"+name+",密码:"+password);
add(info);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
validate();
}
}
}
为什么java程序调不出来
答案:1 悬赏:80 手机版
解决时间 2021-04-14 07:24
- 提问者网友:绫月
- 2021-04-13 19:13
最佳答案
- 五星知识达人网友:煞尾
- 2021-04-13 19:25
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class jinianjun implements ActionListener {
JPanel p = new JPanel();
private JTextField name;//, t2;
JButton nameLabel, pwdLabel, sure, cancel;
JPasswordField password;
private JFrame frm;
public jinianjun(JFrame f, JPanel p) {
this.frm=f;
f.add(p);
p.setLayout(null);
p.setBackground(Color.GRAY);
name = new JTextField(20);
name.setBounds(200, 60, 100, 25);
// t2 = new JTextField(20);
// t2.setBounds(200, 120, 100, 25);
nameLabel = new JButton("我的名字:");
nameLabel.setBounds(100, 60, 100, 25);
pwdLabel = new JButton("我的密码:");
pwdLabel.setBounds(100, 120, 100, 25);
sure = new JButton("确定");
sure.setBounds(100, 200, 80, 25);
sure.addActionListener(this);
cancel = new JButton("取消");
cancel.setBounds(220, 200, 80, 25);
cancel.addActionListener(this);
password = new JPasswordField("qilaoshi");
password.setBounds(200, 120, 100, 25);
p.add(name);
//p.add(t2);
p.add(nameLabel);
p.add(pwdLabel);
p.add(sure);
p.add(cancel);
p.add(password);
f.setVisible(true);
f.setBounds(400, 100, 400, 300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.validate();
}
public static void main(String[] args) {
new jinianjun(new JFrame("我的登录窗口"), new JPanel());
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == sure) {
System.out.println("用户名:" + name.getText());
System.out.println("密码:" + password.getText());
if ("wyjwsj".equals(name.getText().trim())
&& "12345".equals(password.getText().trim())) {
frm.dispose();
new MainFrm("用户界面", name.getText().trim(), password.getText()
.trim());
} else {
JOptionPane.showMessageDialog(null, "用户名或密码不对!");
}
} else if (e.getSource() == cancel) {
System.exit(1);
}
}
// private void dispose() {
// // TODO Auto-generated method stub
//
// }
class MainFrm extends JFrame {
private JLabel info;
public MainFrm(String s, String name, String password) {
super(s);
setBounds(400, 200, 500, 400);
setLayout(new FlowLayout());
info = new JLabel("登陆成功,用户名:" + name + ",密码:" + password);
add(info);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
validate();
}
}
}
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class jinianjun implements ActionListener {
JPanel p = new JPanel();
private JTextField name;//, t2;
JButton nameLabel, pwdLabel, sure, cancel;
JPasswordField password;
private JFrame frm;
public jinianjun(JFrame f, JPanel p) {
this.frm=f;
f.add(p);
p.setLayout(null);
p.setBackground(Color.GRAY);
name = new JTextField(20);
name.setBounds(200, 60, 100, 25);
// t2 = new JTextField(20);
// t2.setBounds(200, 120, 100, 25);
nameLabel = new JButton("我的名字:");
nameLabel.setBounds(100, 60, 100, 25);
pwdLabel = new JButton("我的密码:");
pwdLabel.setBounds(100, 120, 100, 25);
sure = new JButton("确定");
sure.setBounds(100, 200, 80, 25);
sure.addActionListener(this);
cancel = new JButton("取消");
cancel.setBounds(220, 200, 80, 25);
cancel.addActionListener(this);
password = new JPasswordField("qilaoshi");
password.setBounds(200, 120, 100, 25);
p.add(name);
//p.add(t2);
p.add(nameLabel);
p.add(pwdLabel);
p.add(sure);
p.add(cancel);
p.add(password);
f.setVisible(true);
f.setBounds(400, 100, 400, 300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.validate();
}
public static void main(String[] args) {
new jinianjun(new JFrame("我的登录窗口"), new JPanel());
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == sure) {
System.out.println("用户名:" + name.getText());
System.out.println("密码:" + password.getText());
if ("wyjwsj".equals(name.getText().trim())
&& "12345".equals(password.getText().trim())) {
frm.dispose();
new MainFrm("用户界面", name.getText().trim(), password.getText()
.trim());
} else {
JOptionPane.showMessageDialog(null, "用户名或密码不对!");
}
} else if (e.getSource() == cancel) {
System.exit(1);
}
}
// private void dispose() {
// // TODO Auto-generated method stub
//
// }
class MainFrm extends JFrame {
private JLabel info;
public MainFrm(String s, String name, String password) {
super(s);
setBounds(400, 200, 500, 400);
setLayout(new FlowLayout());
info = new JLabel("登陆成功,用户名:" + name + ",密码:" + password);
add(info);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
validate();
}
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯