请看我的代码如下:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MyCompare extends JFrame
{
static String a,b;
static JLabel l1 = new JLabel("请输入您的密码");
static JLabel l2 = new JLabel("请确认您的密码");
static JLabel l3 = new JLabel();
//static JLabel l4 = new JLabel();
static JPasswordField j1 = new JPasswordField();
static JPasswordField j2 = new JPasswordField();
static JButton b1 = new JButton("确认");
static JButton b2 = new JButton("清除");
public MyCompare()
{
super("登陆框");
setBounds(20,20,200,150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
MyCompare m = new MyCompare();
m.getContentPane().add(l1);
m.getContentPane().add(j1);
m.getContentPane().add(l2);
m.getContentPane().add(j2);
m.getContentPane().add(l3);
//m.getContentPane().add(l4);
m.getContentPane().setLayout(new GridLayout(4,2));
m.show();
a = j1.getPassword().toString();
b = j2.getPassword().toString();
b1.addActionListener(new ButtonListener1());
b2.addActionListener(new ButtonListener2());
//frm.getContentPane().setLayout(new GridLayout(4,2));
}
static class ButtonListener1 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(a.equals(b))
{
l3.setText("OK!!");
}
else
{
l3.setText("error!!");
}
}
}
static class ButtonListener2 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
j1.setText(null);
j2.setText(null);
}
}
}我用我的14.1宽屏笔记本运行,每次都是黑屏,在学校的台式机却不是这样,不知道是怎么回事,难道宽屏幕显示器有关系???
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MyCompare extends JFrame
{
static String a,b;
static JLabel l1 = new JLabel("请输入您的密码");
static JLabel l2 = new JLabel("请确认您的密码");
static JLabel l3 = new JLabel();
//static JLabel l4 = new JLabel();
static JPasswordField j1 = new JPasswordField();
static JPasswordField j2 = new JPasswordField();
static JButton b1 = new JButton("确认");
static JButton b2 = new JButton("清除");
public MyCompare()
{
super("登陆框");
setBounds(20,20,200,150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
MyCompare m = new MyCompare();
m.getContentPane().add(l1);
m.getContentPane().add(j1);
m.getContentPane().add(l2);
m.getContentPane().add(j2);
m.getContentPane().add(l3);
//m.getContentPane().add(l4);
m.getContentPane().setLayout(new GridLayout(4,2));
m.show();
a = j1.getPassword().toString();
b = j2.getPassword().toString();
b1.addActionListener(new ButtonListener1());
b2.addActionListener(new ButtonListener2());
//frm.getContentPane().setLayout(new GridLayout(4,2));
}
static class ButtonListener1 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(a.equals(b))
{
l3.setText("OK!!");
}
else
{
l3.setText("error!!");
}
}
}
static class ButtonListener2 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
j1.setText(null);
j2.setText(null);
}
}
}我用我的14.1宽屏笔记本运行,每次都是黑屏,在学校的台式机却不是这样,不知道是怎么回事,难道宽屏幕显示器有关系???
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货