为什么
public class Class1 extends Frame implements WindowListener,MouseListener
出错了
Class1 is not abstact and does not override abstract method mouse
----------------解决方案--------------------------------------------------------
接口的方法必须要实现
即使只是把方法放在那里 里面什么也不做
----------------解决方案--------------------------------------------------------
代码是这样的 看看有什么错的
import java.awt.*;
import java.awt.event.*;
public class class1 extends Frame implements WindowListener,MouseListener{
static class1 mw;
Panel pan1=new Panel();
Panel pan2=new Panel();
Panel pan3=new Panel();
Panel pan4=new Panel();
CardLayout layout=new CardLayout();
public static void main(String args[]){
mw.setpan1();
mw.setpan2();
mw.setpan3();
mw.setpan4();
mw.go();
}
public void go(){
mw=new class1("four layouts");
mw.setLayout(new GridLayout(2,2));
mw.add(pan1);
mw.add(pan2);
mw.add(pan3);
mw.add(pan4);
mw.addWindowListener(mw);
mw.setSize(400,400);
mw.setVisible(true);
}
class1(String str){
super(str);
}
public void setpan1(){
pan1.setLayout(new BorderLayout());
Button b1=new Button("North");
Button b2=new Button("South");
Button b3=new Button("East");
Button b4=new Button("Center");
Button b5=new Button("West");
pan1.add("North",b1);
pan1.add("South",b2);
pan1.add("East",b3);
pan1.add("Center",b4);
pan1.add("West",b5);
}
public void setpan2(){
pan2.setLayout(new GridLayout(2,2));
Button b1=new Button("1");
Button b2=new Button("2");
Button b3=new Button("3");
Button b4=new Button("4");
pan2.add(b1);
pan2.add(b2);
pan2.add(b3);
pan2.add(b4);
}
public void setpan3(){
pan3.setLayout(new FlowLayout());
Button b1=new Button("1");
Button b2=new Button("2");
Button b3=new Button("3");
pan3.add(b1);
pan3.add(b2);
pan3.add(b3);
pan3.setBackground(Color.red);
}
public void setpan4(){
pan4.setLayout(layout);
Button b1=new Button("the fist page");
b1.addMouseListener(this);
Label b2=new Label("the second page");
b2.addMouseListener(this);
pan4.add(b1,"b1");
pan4.add(b2,"b1");
}
public void windowClosing(WindowEvent e){
System.exit(1);
}
public void windowOpened(WindowEvent e){
}
public void windowIconified(WindowEvent e){
}
public void windowDeiconified(WindowEvent e){
}
public void windowClosed(WindowEvent e){
}
public void windowActivated(WindowEvent e){
}
public void windowDeactivated(WindowEvent e){
}
public void mouseClicked(MouseEvent e){
layout.next(pan4);
}
public void mouseEntered(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
public void mousePressde(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
}
}
----------------解决方案--------------------------------------------------------
代码是这样的 看看有什么错的
import java.awt.*;
import java.awt.event.*;
public class class1 extends Frame implements WindowListener,MouseListener{
static class1 mw;
Panel pan1=new Panel();
Panel pan2=new Panel();
Panel pan3=new Panel();
Panel pan4=new Panel();
CardLayout layout=new CardLayout();
public static void main(String args[]){
mw.setpan1();
mw.setpan2();
mw.setpan3();
mw.setpan4();
mw.go();
}
public void go(){
mw=new class1("four layouts");
mw.setLayout(new GridLayout(2,2));
mw.add(pan1);
mw.add(pan2);
mw.add(pan3);
mw.add(pan4);
mw.addWindowListener(mw);
mw.setSize(400,400);
mw.setVisible(true);
}
class1(String str){
super(str);
}
public void setpan1(){
pan1.setLayout(new BorderLayout());
Button b1=new Button("North");
Button b2=new Button("South");
Button b3=new Button("East");
Button b4=new Button("Center");
Button b5=new Button("West");
pan1.add("North",b1);
pan1.add("South",b2);
pan1.add("East",b3);
pan1.add("Center",b4);
pan1.add("West",b5);
}
public void setpan2(){
pan2.setLayout(new GridLayout(2,2));
Button b1=new Button("1");
Button b2=new Button("2");
Button b3=new Button("3");
Button b4=new Button("4");
pan2.add(b1);
pan2.add(b2);
pan2.add(b3);
pan2.add(b4);
}
public void setpan3(){
pan3.setLayout(new FlowLayout());
Button b1=new Button("1");
Button b2=new Button("2");
Button b3=new Button("3");
pan3.add(b1);
pan3.add(b2);
pan3.add(b3);
pan3.setBackground(Color.red);
}
public void setpan4(){
pan4.setLayout(layout);
Button b1=new Button("the fist page");
b1.addMouseListener(this);
Label b2=new Label("the second page");
b2.addMouseListener(this);
pan4.add(b1,"b1");
pan4.add(b2,"b1");
}
public void windowClosing(WindowEvent e){
System.exit(1);
}
public void windowOpened(WindowEvent e){
}
public void windowIconified(WindowEvent e){
}
public void windowDeiconified(WindowEvent e){
}
public void windowClosed(WindowEvent e){
}
public void windowActivated(WindowEvent e){
}
public void windowDeactivated(WindowEvent e){
}
public void mouseClicked(MouseEvent e){
layout.next(pan4);
}
public void mouseEntered(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
public void mousePressde(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
}
}
----------------解决方案--------------------------------------------------------
还是
和原来的一样
千里
你在看看
----------------解决方案--------------------------------------------------------
千里给你标出错误了 mousePressde??
是mousePressed
----------------解决方案--------------------------------------------------------
我服了楼主
----------------解决方案--------------------------------------------------------
惭愧呀
----------------解决方案--------------------------------------------------------
我也服了楼主了,有我当年的犯错误的影子了.呵呵.这个平时多注意一点,以后熟悉了,自然就知道错在什么地方了.
----------------解决方案--------------------------------------------------------
刚才把楼主的代码调试了,eclipse说不对哦,说是空指针.
修改了一下:
import java.awt.*;
import java.awt.event.*;
public class Class1 extends Frame implements WindowListener,MouseListener{
static Class1 mw;
Panel pan1=new Panel();
Panel pan2=new Panel();
Panel pan3=new Panel();
Panel pan4=new Panel();
CardLayout layout=new CardLayout();
public static void main(String args[]){
Class1 mw = new Class1("我的方格");
mw.setpan1();
mw.setpan2();
mw.setpan3();
mw.setpan4();
mw.go();
}
//set the main window formate
public void go(){
// mw=new Class1("four layouts");
mw.setLayout(new GridLayout(2,2));
mw.add(pan1);
mw.add(pan2);
mw.add(pan3);
mw.add(pan4);
mw.addWindowListener(this);//mw
mw.setSize(400,400);
mw.setVisible(true);
}
public Class1 (String str){
super(str);
}
//set panel format
public void setpan1(){
pan1.setLayout(new BorderLayout());
Button b1=new Button("North");
Button b2=new Button("South");
Button b3=new Button("East");
Button b4=new Button("Center");
Button b5=new Button("West");
pan1.add("North",b1);
pan1.add("South",b2);
pan1.add("East",b3);
pan1.add("Center",b4);
pan1.add("West",b5);
}
//set panel2 formate
public void setpan2(){
pan2.setLayout(new GridLayout(2,2));
Button b1=new Button("1");
Button b2=new Button("2");
Button b3=new Button("3");
Button b4=new Button("4");
pan2.add(b1);
pan2.add(b2);
pan2.add(b3);
pan2.add(b4);
}
public void setpan3(){
pan3.setLayout(new FlowLayout());
Button b1=new Button("1");
Button b2=new Button("2");
Button b3=new Button("3");
pan3.add(b1);
pan3.add(b2);
pan3.add(b3);
pan3.setBackground(Color.red);
}
public void setpan4(){
pan4.setLayout(layout);
Button b1=new Button("the fist page");
b1.addMouseListener(this);
Label b2=new Label("the second page");
b2.addMouseListener(this);
pan4.add(b1,"b1");
pan4.add(b2,"b1");
}
//set window actions
public void windowClosing(WindowEvent e){
System.exit(1);
}
public void windowOpened(WindowEvent e){
}
public void windowIconified(WindowEvent e){
}
public void windowDeiconified(WindowEvent e){
}
public void windowClosed(WindowEvent e){
}
public void windowActivated(WindowEvent e){
}
public void windowDeactivated(WindowEvent e){
}
public void mouseClicked(MouseEvent e){
layout.next(pan4);
}
//set mouse action
public void mouseEntered(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
public void mousePressed(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
}
}
----------------解决方案--------------------------------------------------------