注册 登录
编程论坛 JAVA论坛

求大神,关于图形界面设计的

KG爱sky 发布于 2015-09-19 12:52, 735 次点击
程序代码:
import java.awt.*;
import javax.swing.*;
import java.awt.event.* ;
import *;

class Register extends JFrame implements ActionListener
{
    JLabel lab1,lab2,lab3,lab4,lab5,lab6,lab7;
    JTextField text1;
    JPasswordField pass1,pass2;
    JRadioButton r1,r2;
    ButtonGroup group;
    JComboBox box1;
    JCheckBox box2,box3;
    JScrollPane p1;
    JTextArea area;
    JButton b1,b2;
   
   
public Register()
{
    lab1=new JLabel("用户名");
    lab2=new JLabel("密码");
    lab2=new JLabel("确认密码");
    lab3=new JLabel("性别");
    lab4=new JLabel("所在地");
    lab5=new JLabel("兴趣爱好");
    lab7=new JLabel("个人简介");
    text1=new JTextField(15);
    pass1=new JPasswordField(15);
    r1=new JRadioButton("男");
    r2=new JRadioButton("女");
    group=new ButtonGroup();
    group.add(r1);
    group.add(r2);
    r1.setSelected(true);
   
    box1=new JComboBox();
    box1.addItem("广东");
    box1.addItem("广西");
    box1.addItem("湖南");
    box2=new JCheckBox("音乐");
    box2=new JCheckBox("运动");
    p1=new JScrollPane();
    p1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    area=new JTextArea(5,15);
    area.setLineWrap(true);
    p1.getViewport().add(area);
    b1=new JButton("注册");
    b2=new JButton("重填");
    Container con=getContentPane();
    con.setLayout(new FlowLayout());
    con.add(lab1);con.add(text1);
    con.add(lab2);con.add(pass1);
    con.add(lab3);con.add(pass2);
    con.add(lab4);con.add(r1);
    con.add(r2);
    con.add(lab5);con.add(box1);
    con.add(lab6);con.add(box2);con.add(box3);
    con.add(lab7);
    con.add(p1);
    con.add(b1);con.add(b2);
}



public static void main(String[] args)
{
    Register reg=new Register();
    reg.setTitle("用户注册");
    reg.setSize(250,350);
    reg.setVisible(true);
    reg.setDefaultCloseOperation(reg.EXIT_ON_CLOSE);
   
}
}


提示The type Register must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)错误是什么原因??
8 回复
#2
诸葛欧阳2015-09-19 12:54
在添加事件监听器时要实现这个方法
#3
KG爱sky2015-09-19 13:08
回复 2楼 诸葛欧阳
菜鸟一枚,具体是什么意思??
#4
林月儿2015-09-19 13:21
程序代码:
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class Register extends JFrame implements ActionListener
{
    /**
     *
     
*/
    private static final long serialVersionUID = 1L;
    JLabel lab1,lab2,lab3,lab4,lab5,lab6,lab7;
    JTextField text1;
    JPasswordField pass1,pass2;
    JRadioButton r1,r2;
    ButtonGroup group;
    JComboBox<String> box1;
    JCheckBox box2,box3;
    JScrollPane p1;
    JTextArea area;
    JButton b1,b2;
   
   
    public Register()
    {
        lab1=new JLabel("用户名");
        lab2=new JLabel("密码");
        lab3=new JLabel("确认密码");
        lab4=new JLabel("性别");
        lab5=new JLabel("所在地");
        lab6=new JLabel("兴趣爱好");
        lab7=new JLabel("个人简介");
        text1=new JTextField(15);
        pass1=new JPasswordField(15);
        pass2=new JPasswordField(15);
        r1=new JRadioButton("男");
        r2=new JRadioButton("女");
        group=new ButtonGroup();
        group.add(r1);
        group.add(r2);
        r1.setSelected(true);
        
        box1=new JComboBox<String>();
        box1.addItem("广东");
        box1.addItem("广西");
        box1.addItem("湖南");
        box2=new JCheckBox("音乐");
        box3=new JCheckBox("运动");
        p1=new JScrollPane();
        p1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        area=new JTextArea(5,15);
        area.setLineWrap(true);
        p1.getViewport().add(area);
        b1=new JButton("注册");
        b2=new JButton("重填");
        b1.addActionListener(this);
        b2.addActionListener(this);
        Container con=getContentPane();
        con.setLayout(new FlowLayout());
        con.add(lab1);con.add(text1);
        con.add(lab2);con.add(pass1);
        con.add(lab3);con.add(pass2);
        con.add(lab4);con.add(r1);
        con.add(r2);
        con.add(lab5);con.add(box1);
        con.add(lab6);con.add(box2);con.add(box3);
        con.add(new JLabel("  "));
        con.add(lab7);
        con.add(p1);
        con.add(b1);con.add(b2);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==b1)
        {
            JOptionPane.showMessageDialog(null, "注册结束!");
        }
        else if(e.getSource()==b2)
        {
             text1.setText("");;
             pass1.setText("");
             pass2.setText("");
             r1.setSelected(false);
             r2.setSelected(false);
             box2.setSelected(false);
             box3.setSelected(false);
        }
    }
    public static void main(String[] args)
    {
        Register reg=new Register();
        reg.setTitle("用户注册");
        reg.setSize(250,350);
        reg.setVisible(true);
        reg.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
#5
KG爱sky2015-09-19 13:46
回复 4楼 林月儿
谢谢,我去看看
#6
林月儿2015-09-19 19:48
以下是引用KG爱sky在2015-9-19 13:46:37的发言:

谢谢,我去看看


恩,有改动!
#7
KG爱sky2015-09-19 20:36
回复 6楼 林月儿
嗯,知道错哪里了,谢谢!!
#8
LSASTA2015-09-19 23:06
楼主你学到哪儿了 能编出这个东西啊,,我才开始学没几天   请教一下
#9
KG爱sky2015-09-21 10:14
回复 8楼 LSASTA
GUI
1