java程序 有一个错误,不知道什么地方错了,望各位高手帮帮忙,谢谢了!
importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.event.*...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class junber8 extends JFrame implements ActionListener{
private JSplitPane panev,paneh;
private JScrollPane scropane1,scrollpane2;
private JPanel pleft;
private JPanel pright;
private JTextArea textarea1,textarea2;
private JLabel label1,label2;
private JTextField field1,field2;
private JRadioButton radiobutton1,radiobutton2;
private JButton button1,button2;
public junber8(){
super("聊天室");
textarea1=new JTextArea();
textarea1.setEditable(false);
scropane1=new JScrollPane(textarea1);
pleft=new JPanel();
label1=new JLabel("输入");
field1=new JTextField(20);
button1=new JButton("发送");
button1.addActionListener(this);
pleft.add(label1);
pleft.add(field1);
pleft.add(button1);
pright=new JPanel();
label2=new JLabel("性别");
field2=new JTextField("请输入信息");
field2.setFont(new Font("serif",Font.PLAIN,14));
ButtonGroup bg=new ButtonGroup();
radiobutton1=new JRadioButton("男");
radiobutton1.setFont(new Font("serif",Font.PLAIN,14));
radiobutton1.setSelected(true);
radiobutton2=new JRadioButton("女");
radiobutton2.setFont(new Font("serif",Font.PLAIN,14));
button2=new JButton("确定");
bg.add(radiobutton1);
bg.add(radiobutton2);
pright.add(label2);
pright.add(radiobutton1);
pright.add(radiobutton2);
pright.add(field2);
pright.add(button2);
panev=new JSplitPane(JSplitPane.VERTICAL_SPLIT,scropane1,pleft);
panev.setDividerLocation(280);
paneh=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,panev,pright);
paneh.setDividerLocation(350);
this.add(paneh);
this.setSize(600,500);
this.setLocation(300,300);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//setVisible(true);
}
public void actionPeformed(ActionEvent e){
Object source=e.getSource();
//"发送"按钮
if(source==button1){
button1Click();
}
}
public void button1Click(){
String field=field1.getText();
if(field.equals("")){
JOptionPane.showMessageDialog(button1,"内容不能为空","提示",JOptionPane.WARNING_MESSAGE);
return;
}
}
public static void main(String args[]){
junber8 junber=new junber8();
junber.setVisible(true);
}
} 展开
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class junber8 extends JFrame implements ActionListener{
private JSplitPane panev,paneh;
private JScrollPane scropane1,scrollpane2;
private JPanel pleft;
private JPanel pright;
private JTextArea textarea1,textarea2;
private JLabel label1,label2;
private JTextField field1,field2;
private JRadioButton radiobutton1,radiobutton2;
private JButton button1,button2;
public junber8(){
super("聊天室");
textarea1=new JTextArea();
textarea1.setEditable(false);
scropane1=new JScrollPane(textarea1);
pleft=new JPanel();
label1=new JLabel("输入");
field1=new JTextField(20);
button1=new JButton("发送");
button1.addActionListener(this);
pleft.add(label1);
pleft.add(field1);
pleft.add(button1);
pright=new JPanel();
label2=new JLabel("性别");
field2=new JTextField("请输入信息");
field2.setFont(new Font("serif",Font.PLAIN,14));
ButtonGroup bg=new ButtonGroup();
radiobutton1=new JRadioButton("男");
radiobutton1.setFont(new Font("serif",Font.PLAIN,14));
radiobutton1.setSelected(true);
radiobutton2=new JRadioButton("女");
radiobutton2.setFont(new Font("serif",Font.PLAIN,14));
button2=new JButton("确定");
bg.add(radiobutton1);
bg.add(radiobutton2);
pright.add(label2);
pright.add(radiobutton1);
pright.add(radiobutton2);
pright.add(field2);
pright.add(button2);
panev=new JSplitPane(JSplitPane.VERTICAL_SPLIT,scropane1,pleft);
panev.setDividerLocation(280);
paneh=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,panev,pright);
paneh.setDividerLocation(350);
this.add(paneh);
this.setSize(600,500);
this.setLocation(300,300);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//setVisible(true);
}
public void actionPeformed(ActionEvent e){
Object source=e.getSource();
//"发送"按钮
if(source==button1){
button1Click();
}
}
public void button1Click(){
String field=field1.getText();
if(field.equals("")){
JOptionPane.showMessageDialog(button1,"内容不能为空","提示",JOptionPane.WARNING_MESSAGE);
return;
}
}
public static void main(String args[]){
junber8 junber=new junber8();
junber.setVisible(true);
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询