/* Programmer: Maribelle Lacno
* Program name: combinationLock
* Subject: IT134_Computer Programming 3
* Instructor: Mr. Dony Dongiapon
* Date Started: 03/16/09
* Date Finished: 03/18/09
* Purpose: To create a program that will create a frame
* with ten buttons from 0 to 9 and will exit if the user
* click on the correct three buttons in order but if the
* wrong combination is used, the frame will turns red.
*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class combinationLock extends JFrame{
String[] password={"8","4","9"};
int x=0,y=0;
JButton buttons[];
JPanel buttonPanel;
Container container = getContentPane();
public combinationLock(){
super("Combination Lock");
ClickEvent action = new ClickEvent();
container.setLayout(new FlowLayout());
buttons = new JButton[10];
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(0,buttons.length));
for(int x=0;x<10;x++){
if(event.getActionCommand().equals(password[x])){
y+=1;
if(y==3){
System.exit(0);
}
}else{
y+=1;
if(y==3){
container.setBackground(Color.red);
x=-1;
y=-1;
}
}
x++;
}
}
}
}
Friday, March 20, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment