JAVA高低階程式,幫看錯誤

import java.awt.*;

import java.awt.event.*;public class S extends WindowAdapter implements ActionListener, MouseMotionListener, MouseListener

{

Frame f1,f2;

Button b1;

public static void main(String argv[])

{

new S();

} public S()

{

f1 = new Frame("S");

f1.setLayout(new GridLayout(4,1));

f1.addWindowListener(this); f2 = new Frame("SS");

b1 = new Button("Frame");

b1.setActionCommand("b1");

b1.addActionListener(this);

f1.add(b1);

f1.setSize(200, 200);

f1.pack();

f1.setVisible(true);

} public void actionPerformed(ActionEvent e)

{

Button b = (Button) e.getSource();

if (b==b1)

{

f2.setVisible(true);

}

else

f2.setVisible(false);

}

Frame f[];

public static void main (String argv[])

{

new S();

}

public S()

{

System.out.print(roll());

f2 = new Frame[5];

for (int i = 0;i<f.length;i++){

f[i] = new Frame("frame" + (i+1));

f[i].setVisible(true);

f[i].setSize(200,200);

}

}

public int roll()

{

return (int)(Math.random() * 10)+1;

}

}

Update:

編譯出現的錯誤

S.java:48: main(java.lang.String[]) is already defined in S

public static void main (String argv[])

^

S.java:53: S() is already defined in S

public S()

^

Update 2:

S.java:4: S is not abstract and does not override abstract method mouseMoved(jav

a.awt.event.MouseEvent) in java.awt.event.MouseMotionListener

public class S extends WindowAdapter implements ActionListener, MouseMotionListe

ner, MouseListener

^

Update 3:

S.java:56: incompatible types

found : java.awt.Frame[]

required: java.awt.Frame

f2 = new Frame[5];

^

4 errors

Update 4:

我想讓程式執行的時候先只有跑出S的視窗

之後點裡面名為Frame的Button會跑出隨機個Frame

這是我的想法

1 Answer

Rating
  • 10 years ago
    Favorite Answer

    import java.awt.*;

    import java.awt.event.*;

    public class S extends WindowAdapter implements ActionListener//, MouseMotionListener, MouseListener

    {

    Frame f[];

    Frame f1,f2;

    Button b1;

    public static void main(String argv[])

    {

    new S();

    }

    public S()

    {

    System.out.print(roll());

    f = new Frame[5];

    for (int i = 0;i<f.length;i++){

    f[i] = new Frame("frame" + (i+1));

    f[i].setVisible(true);

    f[i].setSize(200,200);

    }

    f1 = new Frame("S");

    f1.setLayout(new GridLayout(4,1));

    f1.addWindowListener(this);

    f2 = new Frame("SS");

    b1 = new Button("Frame");

    b1.setActionCommand("b1");

    b1.addActionListener(this);

    f1.add(b1);

    f1.setSize(200, 200);

    f1.pack();

    f1.setVisible(true);

    }

    public void actionPerformed(ActionEvent e)

    {

    Button b = (Button) e.getSource();

    if (b==b1)

    {

    f2.setVisible(true);

    }

    else

    f2.setVisible(false);

    }

    public int roll()

    {

    return (int)(Math.random() * 10)+1;

    }

    }

    2011-06-02 21:21:38 補充:

    錯很大 看不出你這程式用途是?

    2011-06-03 22:42:57 補充:

    import java.awt.*;

    import java.awt.event.*;

    public class S extends WindowAdapter implements ActionListener

    {

    2011-06-03 22:43:12 補充:

    Frame[] array = new Frame[10];

    Frame f1;

    Button b1;

    public static void main(String argv[])

    {

    new S();

    }

    2011-06-03 22:43:37 補充:

    public S()

    {

    f1 = new Frame("S");

    f1.setLayout(new GridLayout(4,1));

    f1.addWindowListener(this);

    b1 = new Button("Frame");

    b1.setActionCommand("b1");

    b1.addActionListener(this);

    2011-06-03 22:43:50 補充:

    f1.add(b1);

    f1.setSize(200, 200);

    f1.pack();

    f1.setVisible(true);

    }

    public void actionPerformed(ActionEvent e)

    {

    roll();

    }

    2011-06-03 22:44:02 補充:

    public void roll()

    {

    int n = (int)(Math.random() * 10) + 1;

    for (int i = 0;i < n;i++)

    {

    array[i] = new Frame("frame" + (i + 1));

    array[i].setSize(200,200);

    array[i].setVisible(true);

    }

    }

    }

Still have questions? Get your answers by asking now.