回 帖 发 新 帖 刷新版面

主题:GUI 编译不了。找不出问题,希望好心人能指点下

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BorderLayoute JApplet implements ActionListener{

    JButton a1=new JButton("north"),a2=new JButton("south"),
            a3=new JButton("west"),a4=new JButton("east");
    JLable b1=new JLabel("center");
    Container cp=getContentPane();

public void init(){
    cp.setLayout(new BorderLayout(10,10));
    cp.add("North",a1);
    a1.addActionListener(this);
    cp.add("South",a2);
    a2.addActionListener(this);
    cp.add("East",a3);
    a3.addActionListener(this);
    cp.add("West",a4);
    a4.addActionListener(this);
    cp.add("Center",b1);

}
public void actionPerformed(ActionEvent e){
    switch(e.getSource())
    {
    case a1:setText("a1");break;
    case a2:setText("a2");break;
    case a3:setText("a3");break;
    case a4:setText("a4");break;
    }
}
}


C:\Documents and Settings\Administrator\My Documents\BorderLayoute.java:4: 需要 '{'
public class BorderLayoute JApplet implements ActionListener{
                          ^
1 错误

工具以退出代码 1 完成

回复列表 (共2个回复)

沙发

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BorderLayoute extends JApplet implements ActionListener{

    JButton a1=new JButton("north"),a2=new JButton("south"),
            a3=new JButton("west"),a4=new JButton("east");
    JLable b1=new JLabel("center");
    Container cp=getContentPane();

public void init(){
    cp.setLayout(new BorderLayout(10,10));
    cp.add("North",a1);
    a1.addActionListener(this);
    cp.add("South",a2);
    a2.addActionListener(this);
    cp.add("East",a3);
    a3.addActionListener(this);
    cp.add("West",a4);
    a4.addActionListener(this);
    cp.add("Center",b1);

}
public void actionPerformed(ActionEvent e){
    switch(e.getSource())
    {
    case a1:setText("a1");break;
    case a2:setText("a2");break;
    case a3:setText("a3");break;
    case a4:setText("a4");break;
    }
}
}

public class BorderLayoute extends JApplet implements ActionListener{

板凳

正解

我来回复

您尚未登录,请登录后再回复。点此登录或注册