0% found this document useful (0 votes)
30 views3 pages

Juego PDF

This Java code defines a class called Juego that extends the JApplet class. Juego contains code to initialize and run Conway's Game of Life, including arrays to store the game board state, buttons to control the game, and methods to generate new generations and update the displayed board. It sets up a graphical user interface with a panel to display the board, buttons to control the game, and labels to display information.

Uploaded by

Jose Alexis Correa Valencia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

Juego PDF

This Java code defines a class called Juego that extends the JApplet class. Juego contains code to initialize and run Conway's Game of Life, including arrays to store the game board state, buttons to control the game, and methods to generate new generations and update the displayed board. It sets up a graphical user interface with a panel to display the board, buttons to control the game, and labels to display information.

Uploaded by

Jose Alexis Correa Valencia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

C:/Users/Insside/Documents/NetBeansProjects/Systemplus/src/systemplus/Juego.

java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

package systemplus;
import
import
import
import

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

public class Juego extends JApplet {


boolean estacionaria;
boolean negre;
boolean canvi = false;
boolean[][] area2 = new boolean[25][45];
Vida v = null;
boolean clic = false;
Object o;
JLabel aux;
JLabel[][] area = new JLabel[25][45];
private boolean isStandalone = false;
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
GridLayout gridLayout1 = new GridLayout();
JPanel jPanel3 = new JPanel();
JButton seggen = new JButton();
JButton about = new JButton();
JButton borrar = new JButton();
ActionListener al =
new ActionListener() {
public void actionPerformed(ActionEvent e) {
o = e.getSource();
if(o == borrar)
{
for (int i = 0; i < area.length; i++)
for (int j = 0; j < area[0].length; j++)
area[i][j].setBackground(Color.white);
canvi = true;
}
else if(o == about)
mostrarAbout();
else if(o == seggen)
{
if(canvi || v == null)
{
for (int i = 0; i < area2.length; i++)
for (int j = 0; j < area2[0].length; j++) {
if (area[i][j].getBackground().equals(Color.red))
area2[i][j] = true;
else
area2[i][j] = false;
}
canvi = false;
v = new Vida(area2, jCheckBox1.isSelected());
est.setText(Integer.toString(v.calcularEstacionaria()));
estacionaria = true;
if(est.getText().equals("1000"))
{
est.setText("NO");
estacionaria = false;
}
}
area2 = v.seguentGen();
if(estacionaria)
{
if (Integer.parseInt(est.getText()) > 0)
est.setText(Integer.toString(Integer.parseInt(est.getText()) - 1));
}
for(int i = 0; i < area2.length; i++)
for(int j = 0; j < area2[0].length; j++)
{
if(area2[i][j] == true)
area[i][j].setBackground(Color.red);
else
area[i][j].setBackground(Color.white);
}
}
else if(o == jCheckBox1)
{
canvi = true;
}
}
};
MouseListener ml = new MouseListener(){
public void mouseExited(MouseEvent e){
}
public void mouseEntered(MouseEvent e){
if(clic)
{
o = e.getSource();
if(negre)
((JLabel)o).setBackground(Color.red);
else
((JLabel)o).setBackground(Color.white);
}
}
public void mouseReleased(MouseEvent e)
{
clic = false;
}
public void mouseClicked(MouseEvent e){
}
public void mousePressed(MouseEvent e){
canvi = true;
clic = true;
o = e.getSource();
if(e.getButton() == e.BUTTON1)
{
negre = true;
( (JLabel) o).setBackground(Color.red);
}
else if (e.getButton() == e.BUTTON3)
{
negre = false;
( (JLabel) o).setBackground(Color.white);
}
}
};
MouseMotionListener mml = new MouseMotionListener()
{
public void mouseMoved(MouseEvent e)
{
}
public void mouseDragged(MouseEvent e){
}
};
JCheckBox jCheckBox1 = new JCheckBox();
JLabel est = new JLabel();
JPanel jPanel4 = new JPanel();
TitledBorder titledBorder1;
//Get a parameter value

1.1 of 3

2016.10.29 14:56:08

C:/Users/Insside/Documents/NetBeansProjects/Systemplus/src/systemplus/Juego.java
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public Juego() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
jCheckBox1.addActionListener(al);
titledBorder1 = new TitledBorder("");
seggen.addActionListener(al);
this.setSize(new Dimension(420,320));
jPanel1.setLayout(null);
jPanel2.setBackground(Color.blue);
jPanel2.setBorder(BorderFactory.createLineBorder(Color.black));
jPanel2.setBounds(new Rectangle(16, 11, 362, 227));
jPanel2.setLayout(gridLayout1);
gridLayout1.setColumns(45);
gridLayout1.setHgap(0);
gridLayout1.setRows(25);
gridLayout1.setVgap(0);
jPanel3.setBorder(BorderFactory.createRaisedBevelBorder());
jPanel3.setBounds(new Rectangle(19, 268, 384, 39));
jPanel3.setLayout(null);
seggen.setBounds(new Rectangle(182, 6, 83, 26));
seggen.setMargin(new Insets(2, 1, 2, 1));
seggen.setText("Siguiente");
about.setBounds(new Rectangle(345, 9, 28, 20));
about.setToolTipText("");
about.setMargin(new Insets(2, 1, 2, 1));
about.setText("?");
borrar.setText("Limpiar");
borrar.setMargin(new Insets(2, 1, 2, 1));
borrar.setBounds(new Rectangle(86, 6, 83, 26));
jCheckBox1.setText("Punto");
jCheckBox1.setBounds(new Rectangle(10, 10, 71, 18));
est.setFont(new java.awt.Font("Dialog", 1, 12));
est.setBorder(BorderFactory.createRaisedBevelBorder());
est.setPreferredSize(new Dimension(4, 4));
est.setHorizontalAlignment(SwingConstants.CENTER);
est.setText("0");
est.setBounds(new Rectangle(283, 7, 42, 25));
jPanel4.setBackground(new Color(192, 255, 192));
jPanel4.setBorder(BorderFactory.createLoweredBevelBorder());
jPanel4.setBounds(new Rectangle(14, 8, 392, 250));
jPanel4.setLayout(null);
jPanel1.setBorder(BorderFactory.createLineBorder(Color.black));
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel3.add(jCheckBox1, null);
jPanel3.add(est, null);
jPanel3.add(borrar, null);
jPanel3.add(seggen, null);
jPanel3.add(about, null);
jPanel1.add(jPanel4, null);
jPanel4.add(jPanel2, null);
jPanel1.add(jPanel3, null);
for(int i = 0; i < area.length; i++)
for(int j = 0; j < area[0].length; j++)
{
area[i][j] = new JLabel();
area[i][j].setBackground(Color.white);
area[i][j].setOpaque(true);
area[i][j].setBorder(BorderFactory.createLineBorder(Color.black));
area[i][j].addMouseListener(ml);
area[i][j].addMouseMotionListener(mml);
aux = area[i][j];
jPanel2.add(aux);
}
borrar.addActionListener(al);
about.addActionListener(al);
}
//Start the applet
public void start() {
}
//Stop the applet
public void stop() {
}
//Destroy the applet
public void destroy() {
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
//Main method
public static void main(String[] args) {
Juego applet = new Juego();
applet.isStandalone = true;
JFrame frame = new JFrame();
//EXIT_ON_CLOSE == 3
frame.setDefaultCloseOperation(3);
frame.setTitle("EL JUEGO DE LA VIDA - SYSTEMPLUS");
frame.getContentPane().add(applet, BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(440,360);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
frame.setVisible(true);
}
//static initializer for setting look & feel
static {
try {
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch(Exception e) {
}
}
void mostrarAbout()
{
JOptionPane.showMessageDialog(this,"EL JUEGO DE LA VIDA\n\nby Jose Alexis Correa Valencia, 2016. All rights reserved.\n\[email protected]\n\nhttp://www.insside.com","About...",JOptionPane.PLAIN_MESSAGE);
}
}

2.1 of 3

2016.10.29 14:56:08

C:/Users/Insside/Documents/NetBeansProjects/Systemplus/src/systemplus/Juego.java

3.1 of 3

2016.10.29 14:56:08

You might also like