请高手帮忙看一下,这段java代码的问题怎么解决?
importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publicclassL5_12extendsJF...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class L5_12 extends JFrame implements ActionListener{
JPanel p1;
JTextField tf1;
JButton b1,b2;
JComboBox cb;
JTextArea ta;
JScrollPane sp;
String name[]={"闻正","丁香"};
public L5_12(){
this.setTitle("聊天窗口");
this.setSize(400,150);//括号里的数字是像素
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.setLocation(600,300);
this.setResizable(false);
this.setIconImage((new ImageIcon("image\\s.jpg").getImage()));
init();
}
private void init(){
p1=new JPanel();
tf1=new JTextField(10);
b1=new JButton(new ImageIcon("image\\d.jpg"));
b2=new JButton("发送");
cb=new JComboBox(name);
ta=new JTextArea();
sp=new JScrollPane(ta);
addComponents();
}
private void addComponents(){
p1.add(cb); p1.add(tf1);
p1.add(b2); p1.add(b1);
b1.addActionListener(this);
this.add(p1,BorderLayout.SOUTH);
this.add(sp);
}
public void actionPerformed(ActionEvent e){
JFrame in=new JFrame("添加界面");
in.setSize(600,200);
in.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
in.setVisible(true);
in.setLayout(new GridLayout(2,1));
JLabel i=new JLabel("请输入你要添加联系人的名字:");
JTextField tf=new JTextField(6);
JButton b1=new JButton("确定");
JButton b2=new JButton("取消");
JPanel p1=new JPanel();
JPanel p2=new JPanel();
p1.add(i); p1.add(tf);
p2.add(b1); p2.add(b2);
in.add(p1); in.add(p2);
b1.addActionListener(this);
b2.addActionListener(this);
String strs=e.getActionCommand();
if(strs.equals("确定")){
for(int g=2;g<99999;g++){
name[g]=tf.getText();
JFrame f=new JFrame();
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setSize(300,150);
f.setLocation(400,200);
JLabel p=new JLabel("添加成功!");
f.add(p);
break;
}
}else if(strs.equals("取消")){
in.setVisible(false);
}
}
public static void main(String[] args){
L5_12 s=new L5_12();
}
}
老出现异常,怎么解决? 展开
import java.awt.*;
import java.awt.event.*;
public class L5_12 extends JFrame implements ActionListener{
JPanel p1;
JTextField tf1;
JButton b1,b2;
JComboBox cb;
JTextArea ta;
JScrollPane sp;
String name[]={"闻正","丁香"};
public L5_12(){
this.setTitle("聊天窗口");
this.setSize(400,150);//括号里的数字是像素
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.setLocation(600,300);
this.setResizable(false);
this.setIconImage((new ImageIcon("image\\s.jpg").getImage()));
init();
}
private void init(){
p1=new JPanel();
tf1=new JTextField(10);
b1=new JButton(new ImageIcon("image\\d.jpg"));
b2=new JButton("发送");
cb=new JComboBox(name);
ta=new JTextArea();
sp=new JScrollPane(ta);
addComponents();
}
private void addComponents(){
p1.add(cb); p1.add(tf1);
p1.add(b2); p1.add(b1);
b1.addActionListener(this);
this.add(p1,BorderLayout.SOUTH);
this.add(sp);
}
public void actionPerformed(ActionEvent e){
JFrame in=new JFrame("添加界面");
in.setSize(600,200);
in.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
in.setVisible(true);
in.setLayout(new GridLayout(2,1));
JLabel i=new JLabel("请输入你要添加联系人的名字:");
JTextField tf=new JTextField(6);
JButton b1=new JButton("确定");
JButton b2=new JButton("取消");
JPanel p1=new JPanel();
JPanel p2=new JPanel();
p1.add(i); p1.add(tf);
p2.add(b1); p2.add(b2);
in.add(p1); in.add(p2);
b1.addActionListener(this);
b2.addActionListener(this);
String strs=e.getActionCommand();
if(strs.equals("确定")){
for(int g=2;g<99999;g++){
name[g]=tf.getText();
JFrame f=new JFrame();
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setSize(300,150);
f.setLocation(400,200);
JLabel p=new JLabel("添加成功!");
f.add(p);
break;
}
}else if(strs.equals("取消")){
in.setVisible(false);
}
}
public static void main(String[] args){
L5_12 s=new L5_12();
}
}
老出现异常,怎么解决? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询