Comecei usando a interface grafica que o NetBeans tem, usando JFrame, só que depois passei editar o codigo na mão mesmo utilizando o eclipse, eu tenho que fazer um botão piscar para implementar o jogo Genius, primeiramente eu so queria fazer ele piscar, para depois usar as estruturas de dados e fazer o que realmente deve ser feito, só que nem piscar eu to conseguindo fazer, o código ta um pouco extenso, tem muita coisa desnecessária que veio da interface do NetBeans.
import java.awt.Color;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JOptionPane;
//import java.util.Stack;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Jonathas
*/
public class NewJFrame extends javax.swing.JFrame implements Jogo1
{
//private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 1L;
public NewJFrame()
{
initComponents();
}
/**
* 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
public void initComponents()
{
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
jButton5 = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jRadioButton5 = new javax.swing.JRadioButton("Tamanho 8",true);
jRadioButton6 = new javax.swing.JRadioButton("Tamanho 14",false);
jRadioButton7 = new javax.swing.JRadioButton("Tamanho 20",false);
jRadioButton8 = new javax.swing.JRadioButton("Tamanho 31:",false);
radioGroup = new ButtonGroup();
radioGroup.add(jRadioButton5);
radioGroup.add(jRadioButton6);
radioGroup.add(jRadioButton7);
radioGroup.add(jRadioButton8);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(0, 0, 0));
setPreferredSize(new java.awt.Dimension(600, 600));
jPanel1.setBackground(new java.awt.Color(0, 0, 0));
jPanel1.setForeground(new java.awt.Color(51, 255, 0));
jPanel1.setPreferredSize(new java.awt.Dimension(600, 600));
jPanel2.setBackground(new java.awt.Color(204, 204, 255));
jPanel2.setPreferredSize(new java.awt.Dimension(300, 300));
jLabel1.setForeground(new java.awt.Color(204, 204, 255));
jLabel1.setText("jLabel1");
jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
jLabel1MouseEntered(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
jLabel1MouseExited(evt);
}
});
jLabel2.setBackground(new java.awt.Color(0, 51, 255));
jLabel2.setForeground(new java.awt.Color(204, 204, 255));
jLabel2.setText("jLabel2");
jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabel2MouseClicked(evt);
}
public void mousePressed(java.awt.event.MouseEvent evt) {
jLabel2MousePressed(evt);
}
});
jButton1.setBackground(Color.RED);
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jButton1MousePressed(evt);
}
public void mouseReleased(java.awt.event.MouseEvent evt) {
jButton1MouseReleased(evt);
}
});
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setBackground(new java.awt.Color(0, 0, 255));
jButton3.setBackground(new java.awt.Color(255, 255, 0));
jButton4.setBackground(new java.awt.Color(0, 255, 0));
jLabel3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
jLabel3.setText("Tipo de jogo:");
jButton5.setText("1");
jButton5.setToolTipText("Repita a sequencia");
jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jButton5MousePressed(evt);
}
});
jLabel4.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
jLabel4.setText("Selecione o nivel de dificuldade:");
jButton6.setText("2");
jButton6.setToolTipText("Crie sua propria sequencia");
jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jButton6MousePressed(evt);
}
});
jButton7.setText("3");
jButton7.setToolTipText("Repita a sequencia, porém apertando um unico botão");
jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jButton7MousePressed(evt);
}
});
jRadioButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton5ActionPerformed(evt);
}
});
jRadioButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton6ActionPerformed(evt);
}
});
jRadioButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton7ActionPerformed(evt);
}
});
jRadioButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton8ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(8, 8, 8)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton5)
.addComponent(jButton6)
.addComponent(jButton7)
.addComponent(jLabel3)
.addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(120, 120, 120)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(47, 47, 47)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel4)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jRadioButton5)
.addGap(24, 24, 24)
.addComponent(jRadioButton6))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jRadioButton7)
.addGap(18, 18, 18)
.addComponent(jRadioButton8)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 4, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())))))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(226, 226, 226)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGap(105, 105, 105)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(11, 11, 11)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton5, javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jRadioButton5)
.addComponent(jRadioButton6)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton6)
.addComponent(jRadioButton7)
.addComponent(jRadioButton8))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton7)))
.addGap(32, 32, 32))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(24, 24, 24)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 546, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(30, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 560, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(29, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
pack();
}//fim de init
private void jLabel1MouseExited(java.awt.event.MouseEvent evt)
{
//jPanel2.setBackground(new java.awt.Color(204, 204, 255));
//jLabel1.setForeground(new java.awt.Color(204, 204, 204));
//jButton1.setVisible(true);
//jButton2.setVisible(true);
//jButton3.setVisible(true);
//jButton4.setVisible(true);
}
public void jLabel1MouseEntered(java.awt.event.MouseEvent evt) {
jPanel2.setBackground(Color.black);
jLabel1.setForeground(Color.black);
jLabel2.setForeground(Color.black);
jButton1.setVisible(false);
jButton2.setVisible(false);
jButton3.setVisible(false);
jButton4.setVisible(false);
jButton5.setVisible(false);
jButton6.setVisible(false);
jButton7.setVisible(false);
jRadioButton5.setVisible(false);
jRadioButton6.setVisible(false);
jRadioButton7.setVisible(false);
jRadioButton8.setVisible(false);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {
}
public void jLabel2MousePressed(java.awt.event.MouseEvent evt) {
jPanel2.setBackground(new java.awt.Color(204, 204, 255));
jLabel1.setForeground(new java.awt.Color(204, 204, 255));
jLabel2.setForeground(new java.awt.Color(204, 204, 255));
jButton1.setVisible(true);
jButton2.setVisible(true);
jButton3.setVisible(true);
jButton4.setVisible(true);
jButton5.setVisible(true);
jButton6.setVisible(true);
jButton7.setVisible(true);
jRadioButton5.setVisible(true);
jRadioButton6.setVisible(true);
jRadioButton7.setVisible(true);
jRadioButton8.setVisible(true);
}
public void jButton1MousePressed(java.awt.event.MouseEvent evt)
{
jButton1.setBackground( Color.black);
}
public void jButton1MouseReleased(java.awt.event.MouseEvent evt) {
jButton1.setBackground( new Color( 255, 0, 0 ) ); //vermelho normal
}
public void jButton5MousePressed(java.awt.event.MouseEvent evt)
{
if(jRadioButton5.isSelected()==true)
{
//JOptionPane.showMessageDialog(null, "Voce selecionou sequencia com tamanho 8");
//comecaJogo1T(8);
Pisca();
//Pisca2();
}
else if((jRadioButton6.isSelected()==true))
{
JOptionPane.showMessageDialog(null, "Repetir sequencia com tamanho 14");
//jogo1.setTamanho(14);
}
else if((jRadioButton7.isSelected()==true))
{
JOptionPane.showMessageDialog(null, "Repetir sequencia com tamanho 20");
// jogo1.setTamanho(8);
}
else if((jRadioButton8.isSelected()==true))
{
JOptionPane.showMessageDialog(null, "Repetir sequencia com tamanho 31");
}
}
// private void jogo1(int i) {
// // TODO Auto-generated method stub
// }
private void jButton6MousePressed(java.awt.event.MouseEvent evt)
{
if(jRadioButton5.isSelected()==true)
{
JOptionPane.showMessageDialog(null, "Criar sequencia com tamanho 8");
}
else if((jRadioButton6.isSelected()==true))
{
JOptionPane.showMessageDialog(null, "Criar sequencia com tamanho 14");
}
else if((jRadioButton7.isSelected()==true))
{
JOptionPane.showMessageDialog(null, "Criar sequencia com tamanho 20");
}
else if((jRadioButton8.isSelected()==true))
{
JOptionPane.showMessageDialog(null, "Criar sequencia com tamanho 31");
}
}
private void jButton7MousePressed(java.awt.event.MouseEvent evt)
{
if(jRadioButton5.isSelected()==true)
{
JOptionPane.showMessageDialog(null, "Repetir sequencia de uma cor com tamanho 8");
}
else if((jRadioButton6.isSelected()==true))
{
JOptionPane.showMessageDialog(null, "Repetir sequencia de uma cor com tamanho 14");
}
else if((jRadioButton7.isSelected()==true))
{
JOptionPane.showMessageDialog(null, "Repetir sequencia de uma cor com tamanho 20");
}
else if((jRadioButton8.isSelected()==true))
{
JOptionPane.showMessageDialog(null, "Repetir sequencia de uma cor com tamanho 31");
}
}
private void jRadioButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jRadioButton6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jRadioButton7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jRadioButton8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
// private void alteraJogo1(int t)
//{
//}
/**
* @param args the command line arguments
*/
static Thread t = Thread.currentThread( );
private ButtonGroup radioGroup;
// Variables declaration - do not modify
public javax.swing.JButton jButton1;
public javax.swing.JButton jButton2;
public javax.swing.JButton jButton3;
public javax.swing.JButton jButton4;
public javax.swing.JButton jButton5;
public javax.swing.JButton jButton6;
public javax.swing.JButton jButton7;
public javax.swing.JLabel jLabel1;
public javax.swing.JLabel jLabel2;
public javax.swing.JLabel jLabel3;
public javax.swing.JLabel jLabel4;
public javax.swing.JPanel jPanel1;
public javax.swing.JPanel jPanel2;
public javax.swing.JRadioButton jRadioButton5;
public javax.swing.JRadioButton jRadioButton6;
public javax.swing.JRadioButton jRadioButton7;
public javax.swing.JRadioButton jRadioButton8;
//public Jogo1 jogo1;
// End of variables declaration
public void Pisca()
{
try
{
jButton1.setBackground( new Color(255,110,110)); //muda o botao para vermelho claro
Thread.sleep( 500 ); //Pausa a tela por meio segundo
jButton1.setBackground( new Color( 255, 0, 0 ) ); //volta para o vermelho original
}
catch (InterruptedException ie)
{
return;
}
}
@Override
public void comecaJogo1T(int t) // vou usar a variavel t mais a frente
{
Pisca();
}
}