PDA

View Full Version : Ignore this


coeprobf
08-09-2006, 01:16 PM
Please ignore this, me and my friend need to move code from 1 computer to another.

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class LightsOut implements ActionListener
{
private JFrame yourFrame=null;
private JButton yourButton=null;
private JButton yourButton2=null;
private JButton yourButton3=null;
private JButton yourButton4=null;
private JButton yourButton5=null;
private JButton yourButton6=null;
private JButton yourButton7=null;
private JButton yourButton8=null;
public LightsOut()
{
yourFrame=new JFrame("Hello Everybody!");
JPanel yourPanel=new JPanel(new GridLayout(2,2));

yourButton=new JButton("click me!");
yourButton.addActionListener(this);
yourPanel.add(yourButton);
yourButton.setActionCommand("b1");
yourButton.setBackground(Color.blue);

yourButton2=new JButton("No! Click me!");
yourButton2.addActionListener(this);
yourPanel.add(yourButton2);
yourButton2.setActionCommand("b2");
yourButton2.setBackground(Color.blue);

yourButton3=new JButton("Haha, I Win!");
yourButton3.addActionListener(this);
yourPanel.add(yourButton3);
yourButton3.setActionCommand("b3");
yourButton3.setBackground(Color.blue);

yourButton4=new JButton("a");
yourButton4.addActionListener(this);
yourPanel.add(yourButton4);
yourButton4.setActionCommand("b4");
yourButton4.setBackground(Color.blue);

yourButton5=new JButton("s");
yourButton5.addActionListener(this);
yourPanel.add(yourButton5);
yourButton5.setActionCommand("b5");
yourButton5.setBackground(Color.blue);

yourButton6=new JButton("d");
yourButton6.addActionListener(this);
yourPanel.add(yourButton6);
yourButton6.setActionCommand("b6");
yourButton6.setBackground(Color.blue);

yourButton7=new JButton("f");
yourButton7.addActionListener(this);
yourPanel.add(yourButton7);
yourButton7.setActionCommand("b7");
yourButton7.setBackground(Color.blue);

yourButton8=new JButton("g");
yourButton8.addActionListener(this);
yourPanel.add(yourButton8);
yourButton8.setActionCommand("b8");
yourButton8.setBackground(Color.blue);
yourFrame.setContentPane(yourPanel);
yourFrame.pack();
yourFrame.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String ac=e.getActionCommand();
if (ac.equals("b1"))
{
changeColor(yourButton);
}
else if(ac.equals("b2"))
{
changeColor(yourButton2);
}
else if(ac.equals("b3"))
{
changeColor(yourButton3);
}
else if(ac.equals("b4"))
{
changeColor(yourButton4);
}
else if(ac.equals("b5"))
{
changeColor(yourButton5);
}

else if(ac.equals("b6"))
{
changeColor(yourButton6);
}
else if(ac.equals("b7"))
{
changeColor(yourButton7);
}
else if(ac.equals("b8"))
{
changeColor(yourButton8);
}
else
{
System.out.println("Invalid Command");
}

}
public void changeColor(JButton button)
{
if (button.getBackground()==Color.blue)
{
button.setBackground(Color.blue);
}
else
{
button.setBackground(Color.blue);
}
}
public static void main (String args[])
{
SwingApp sa=new SwingApp();
}

}

KrzyMoose
08-11-2006, 12:39 PM
I'm going to remove this in a couple of days, so do what you need to do before then.