In this application I have created the 4 thread
each thread has its own motion speed, when the moving thread getting closer to the
bottom slide so the Y of moving thread and x of bottom slide is matching then bottom slide eats the moving thread.
Output :
Root structure:
Create a folder in any drive and rename it as FruitGame as in below diagram
GUI code:
Download these images and place in the folder images inside the FruitGame folder.
each thread has its own motion speed, when the moving thread getting closer to the
bottom slide so the Y of moving thread and x of bottom slide is matching then bottom slide eats the moving thread.
Output :
Root structure:
Create a folder in any drive and rename it as FruitGame as in below diagram
GUI code:
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
/**
*
* @author rasool.bux
*/
public final class FruitGameJFrame extends javax.swing.JFrame implements MouseMotionListener {
int scoreVal;
int counter = 4;
int x;
ImageIcon icon1 = new ImageIcon("images/strawbary.PNG");
ImageIcon icon2 = new ImageIcon("images/khopra.PNG");
ImageIcon icon3 = new ImageIcon("images/apple1.PNG");
ImageIcon icon4 = new ImageIcon("images/banana.PNG");
/**
* Creates consturctor FruitGameJFrame()
*/
public FruitGameJFrame() {
initComponents();
addMouseMotionListener(this);
this.setSize(600, 600);
this.oneLabel.setIcon(icon1);
this.twoLabel.setIcon(icon2);
this.threeLabel.setIcon(icon3);
this.fourLabel.setIcon(icon4);
this.getContentPane().setBackground(Color.white);
thread1.start();
thread2.start();
thread3.start();
thread4.start();
}
@Override
public void mouseDragged(MouseEvent e) {
System.out.println("Mouse Dragged");
}
@Override
public void mouseMoved(MouseEvent e) {
x = e.getX();
if(x<=486) {
moveButton.setLocation(x,500);
}
}
Thread thread1 = new Thread(){
int value=120;
public void run() {
for(int i=0; i<600; i++) {
oneLabel.setLocation(value, i);
try {
Thread.sleep(25);
} catch (InterruptedException ex) {
Logger.getLogger(FruitGameJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
if(i==560) {
i=0;
}
int valofY = oneLabel.getY();
int valofX = moveButton.getX();
if(valofY==458 ) {
if(valofX>=34 && valofX<=180) {
counter--;
scoreVal+=10;
oneLabel.setVisible(false);
values();
thread1.stop();
}
}
moveButton.setLocation(x,500);
}//end of loop
}
};
Thread thread2 = new Thread(){
public void run() {
for(int i=0; i<600; i++) {
twoLabel.setLocation(320, i);
try {
Thread.sleep(20);
} catch (InterruptedException ex) {
Logger.getLogger(FruitGameJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
if(i==560) {
i=0;
}
int valofY = twoLabel.getY();
int valofX = moveButton.getX();
if(valofY==448) {
if(valofX>=232 && valofX<=382) {
counter--;
scoreVal+=10;
twoLabel.setVisible(false);
values();
thread2.stop();
}
}
moveButton.setLocation(x,500);
}//end of loop
}
};
Thread thread3 = new Thread(){
@Override
public void run() {
for(int i=0; i<600; i++) {
threeLabel.setLocation(410, i);
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
Logger.getLogger(FruitGameJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
if(i==560) {
i=0;
}
int valofY = threeLabel.getY();
int valofX = moveButton.getX();
if(valofY==420) {
if(valofX>=333 && valofX<=485) {
counter--;
scoreVal+=10;
threeLabel.setVisible(false);
values();
thread3.stop();
}
} moveButton.setLocation(x,500);
}//end of loop
}
};
Thread thread4 = new Thread(){
@Override
public void run() {
for(int i=0; i<600; i++) {
fourLabel.setLocation(6, i);
try {
Thread.sleep(15);
} catch (InterruptedException ex) {
Logger.getLogger(FruitGameJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
if(i==560) {
i=0;
}
int valofY = fourLabel.getY();
int valofX = moveButton.getX();
if(valofY==460) {
if(valofX>=8 && valofX<=50) {
counter--;
scoreVal+=10;
fourLabel.setVisible(false);
values();
thread4.stop();
}
} moveButton.setLocation(x,500);
}//end of loop
}
};
public void values() {
this.setTitle("Score : "+scoreVal);
if(counter==0) {
this.getContentPane().setBackground(Color.red);
this.gameOverLabel.setText("Total Score : "+scoreVal);
moveButton.setLocation(x,500);
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
private void initComponents() {
moveButton = new javax.swing.JButton();
oneLabel = new javax.swing.JLabel();
twoLabel = new javax.swing.JLabel();
threeLabel = new javax.swing.JLabel();
gameOverLabel = new javax.swing.JLabel();
fourLabel = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
newGameMenuItem = new javax.swing.JMenuItem();
StopMenuItem = new javax.swing.JMenuItem();
resumeMenuItem = new javax.swing.JMenuItem();
exitMenuItem = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Fruit Game");
setBackground(new java.awt.Color(255, 255, 255));
gameOverLabel.setFont(new java.awt.Font("Times New Roman", 1, 48)); // NOI18N
gameOverLabel.setForeground(new java.awt.Color(255, 255, 255));
fourLabel.setText("jLabel1");
jMenu1.setText("File");
newGameMenuItem.setText("New Game");
newGameMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
newGameMenuItemActionPerformed(evt);
}
});
jMenu1.add(newGameMenuItem);
StopMenuItem.setText("Stop");
StopMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
StopMenuItemActionPerformed(evt);
}
});
jMenu1.add(StopMenuItem);
resumeMenuItem.setText("Resume");
resumeMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resumeMenuItemActionPerformed(evt);
}
});
jMenu1.add(resumeMenuItem);
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitMenuItemActionPerformed(evt);
}
});
jMenu1.add(exitMenuItem);
jMenuBar1.add(jMenu1);
jMenu2.setText("Edit");
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(299, 299, 299)
.addComponent(twoLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 89, Short.MAX_VALUE)
.addComponent(threeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(30, 30, 30)
.addComponent(moveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(120, 120, 120)
.addComponent(oneLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(0, 0, Short.MAX_VALUE)))
.addGap(108, 108, 108))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(gameOverLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 472, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(fourLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(oneLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(40, 40, 40)
.addComponent(twoLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(threeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(2, 2, 2)
.addComponent(fourLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 80, Short.MAX_VALUE)
.addComponent(gameOverLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(106, 106, 106)
.addComponent(moveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}
private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showConfirmDialog(null, "Do You want to Exit");
System.exit(0);
}
private void newGameMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
this.setVisible(false);
FruitGameJFrame fruitGameJFrame = new FruitGameJFrame();
fruitGameJFrame.setVisible(true);
}
private void StopMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
thread1.suspend();
thread2.suspend();
thread3.suspend();
thread4.suspend();
}
private void resumeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
thread1.resume();
thread2.resume();
thread3.resume();
thread4.resume();
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(FruitGameJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(FruitGameJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FruitGameJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(FruitGameJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new FruitGameJFrame().setVisible(true);
}
});
}
private javax.swing.JMenuItem StopMenuItem;
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JLabel fourLabel;
private javax.swing.JLabel gameOverLabel;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JButton moveButton;
private javax.swing.JMenuItem newGameMenuItem;
private javax.swing.JLabel oneLabel;
private javax.swing.JMenuItem resumeMenuItem;
private javax.swing.JLabel threeLabel;
private javax.swing.JLabel twoLabel;
}
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
/**
*
* @author rasool.bux
*/
public final class FruitGameJFrame extends javax.swing.JFrame implements MouseMotionListener {
int scoreVal;
int counter = 4;
int x;
ImageIcon icon1 = new ImageIcon("images/strawbary.PNG");
ImageIcon icon2 = new ImageIcon("images/khopra.PNG");
ImageIcon icon3 = new ImageIcon("images/apple1.PNG");
ImageIcon icon4 = new ImageIcon("images/banana.PNG");
/**
* Creates consturctor FruitGameJFrame()
*/
public FruitGameJFrame() {
initComponents();
addMouseMotionListener(this);
this.setSize(600, 600);
this.oneLabel.setIcon(icon1);
this.twoLabel.setIcon(icon2);
this.threeLabel.setIcon(icon3);
this.fourLabel.setIcon(icon4);
this.getContentPane().setBackground(Color.white);
thread1.start();
thread2.start();
thread3.start();
thread4.start();
}
@Override
public void mouseDragged(MouseEvent e) {
System.out.println("Mouse Dragged");
}
@Override
public void mouseMoved(MouseEvent e) {
x = e.getX();
if(x<=486) {
moveButton.setLocation(x,500);
}
}
Thread thread1 = new Thread(){
int value=120;
public void run() {
for(int i=0; i<600; i++) {
oneLabel.setLocation(value, i);
try {
Thread.sleep(25);
} catch (InterruptedException ex) {
Logger.getLogger(FruitGameJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
if(i==560) {
i=0;
}
int valofY = oneLabel.getY();
int valofX = moveButton.getX();
if(valofY==458 ) {
if(valofX>=34 && valofX<=180) {
counter--;
scoreVal+=10;
oneLabel.setVisible(false);
values();
thread1.stop();
}
}
moveButton.setLocation(x,500);
}//end of loop
}
};
Thread thread2 = new Thread(){
public void run() {
for(int i=0; i<600; i++) {
twoLabel.setLocation(320, i);
try {
Thread.sleep(20);
} catch (InterruptedException ex) {
Logger.getLogger(FruitGameJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
if(i==560) {
i=0;
}
int valofY = twoLabel.getY();
int valofX = moveButton.getX();
if(valofY==448) {
if(valofX>=232 && valofX<=382) {
counter--;
scoreVal+=10;
twoLabel.setVisible(false);
values();
thread2.stop();
}
}
moveButton.setLocation(x,500);
}//end of loop
}
};
Thread thread3 = new Thread(){
@Override
public void run() {
for(int i=0; i<600; i++) {
threeLabel.setLocation(410, i);
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
Logger.getLogger(FruitGameJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
if(i==560) {
i=0;
}
int valofY = threeLabel.getY();
int valofX = moveButton.getX();
if(valofY==420) {
if(valofX>=333 && valofX<=485) {
counter--;
scoreVal+=10;
threeLabel.setVisible(false);
values();
thread3.stop();
}
} moveButton.setLocation(x,500);
}//end of loop
}
};
Thread thread4 = new Thread(){
@Override
public void run() {
for(int i=0; i<600; i++) {
fourLabel.setLocation(6, i);
try {
Thread.sleep(15);
} catch (InterruptedException ex) {
Logger.getLogger(FruitGameJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
if(i==560) {
i=0;
}
int valofY = fourLabel.getY();
int valofX = moveButton.getX();
if(valofY==460) {
if(valofX>=8 && valofX<=50) {
counter--;
scoreVal+=10;
fourLabel.setVisible(false);
values();
thread4.stop();
}
} moveButton.setLocation(x,500);
}//end of loop
}
};
public void values() {
this.setTitle("Score : "+scoreVal);
if(counter==0) {
this.getContentPane().setBackground(Color.red);
this.gameOverLabel.setText("Total Score : "+scoreVal);
moveButton.setLocation(x,500);
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
private void initComponents() {
moveButton = new javax.swing.JButton();
oneLabel = new javax.swing.JLabel();
twoLabel = new javax.swing.JLabel();
threeLabel = new javax.swing.JLabel();
gameOverLabel = new javax.swing.JLabel();
fourLabel = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
newGameMenuItem = new javax.swing.JMenuItem();
StopMenuItem = new javax.swing.JMenuItem();
resumeMenuItem = new javax.swing.JMenuItem();
exitMenuItem = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Fruit Game");
setBackground(new java.awt.Color(255, 255, 255));
gameOverLabel.setFont(new java.awt.Font("Times New Roman", 1, 48)); // NOI18N
gameOverLabel.setForeground(new java.awt.Color(255, 255, 255));
fourLabel.setText("jLabel1");
jMenu1.setText("File");
newGameMenuItem.setText("New Game");
newGameMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
newGameMenuItemActionPerformed(evt);
}
});
jMenu1.add(newGameMenuItem);
StopMenuItem.setText("Stop");
StopMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
StopMenuItemActionPerformed(evt);
}
});
jMenu1.add(StopMenuItem);
resumeMenuItem.setText("Resume");
resumeMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resumeMenuItemActionPerformed(evt);
}
});
jMenu1.add(resumeMenuItem);
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitMenuItemActionPerformed(evt);
}
});
jMenu1.add(exitMenuItem);
jMenuBar1.add(jMenu1);
jMenu2.setText("Edit");
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(299, 299, 299)
.addComponent(twoLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 89, Short.MAX_VALUE)
.addComponent(threeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(30, 30, 30)
.addComponent(moveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(120, 120, 120)
.addComponent(oneLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(0, 0, Short.MAX_VALUE)))
.addGap(108, 108, 108))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(gameOverLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 472, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(fourLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(oneLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(40, 40, 40)
.addComponent(twoLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(threeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(2, 2, 2)
.addComponent(fourLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 80, Short.MAX_VALUE)
.addComponent(gameOverLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(106, 106, 106)
.addComponent(moveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}
private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showConfirmDialog(null, "Do You want to Exit");
System.exit(0);
}
private void newGameMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
this.setVisible(false);
FruitGameJFrame fruitGameJFrame = new FruitGameJFrame();
fruitGameJFrame.setVisible(true);
}
private void StopMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
thread1.suspend();
thread2.suspend();
thread3.suspend();
thread4.suspend();
}
private void resumeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
thread1.resume();
thread2.resume();
thread3.resume();
thread4.resume();
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(FruitGameJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(FruitGameJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FruitGameJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(FruitGameJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new FruitGameJFrame().setVisible(true);
}
});
}
private javax.swing.JMenuItem StopMenuItem;
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JLabel fourLabel;
private javax.swing.JLabel gameOverLabel;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JButton moveButton;
private javax.swing.JMenuItem newGameMenuItem;
private javax.swing.JLabel oneLabel;
private javax.swing.JMenuItem resumeMenuItem;
private javax.swing.JLabel threeLabel;
private javax.swing.JLabel twoLabel;
}
Download these images and place in the folder images inside the FruitGame folder.
No comments:
Post a Comment