检测时老有错误,
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class c11_15 implements ActionListener{
String s1=" ";
JFrame f=null;
JLabel lb=new JLabel("请登录:");
JTextField tf1,tf2;//声明对话框中的文本框对象
JDialog dialog;//声明对话框对象
public c11_15()
{
f = new JFrame("请登录:");
Container cp = f.getContentPane();
/*错误处1*/ JPanel pa = new JPanel(new GirdLayout(3,1));
pa.add(lb);
JButton bt = new JButton("进入登录:");
bt.addActionListener(this);
pa.add(bt);
bt = new JButton("结束");
bt.addActionListener(this);
pa.add(bt);
pa.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.blue,3),"进入登录",TitledBorder.CENTER,TitledBorder.TOP));
cp.add(pa,BorderLayout.CENTER);
f.pack();
f.setVisible(true);
f.addWindowListener(new WinLis());
}
public void actionPerformer(ActionEvent e)
{
String cmd=e.getActionCommand();
if (cmd.equals("进入对话框:"))
{
dial();}//在该方法中创建对话框
else if(cmd.equals("结束!"))
{ }
else if(cmd.equals("返回!"))
{
s1=tf1.getText();
s1=s1+tf2.getText();
lb.setText(s1);dialog.dispose();
}
}
class WinLis extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
public static void main(String args[])
{
new c11_15 ();
}
public void dial()
{
dialog=new JDialog(f,"进入对话框",true);//创建对话框对象
Container diacp=dialog.getContentPane();//创建对话框的容器对象
diacp.setLayout(new FlowLayout());//设置所创建对话框的容器的布局
JLabel lb1=new JLabel("用户名:");
JLabel lb2=new JLabel("口 令:");
JPanel pa1=new JPanel(new GirdLayout(3,2));//面板布局为3行2列布局
tf1=new JTextField(8);
tf2=new JTextField(8);
pa1.add(lb1);
pa1.add(tf1);
pa1.add(lb2);
pa1.add(tf2);
JButton bt1=new JButton("确定");
pa1.add(bt1);
bt1=new JButton("返回");
bt1.addActionListener(this);
pa1.add(bt1);
diacp.add(pa1);//在对话框的容器上放入面板
dialog.setBounds(150,150,200,150);//设置对话框的容器的大小
dialog.setVisible(true);//将对话框变为可见
}
}