Author Topic: java giant button glitch  (Read 2173 times)

0 Members and 1 Guest are viewing this topic.

Offline Snake X

  • Ancient Veteran
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 810
  • Rating: +33/-8
    • View Profile
java giant button glitch
« on: May 25, 2011, 08:34:53 pm »
My friend saved his project to my computer so that I could try to get help for him. He is working on a slot machine and however.. The only button added fills the whole entire screen :crazy:

Code: [Select]
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
import java.util.*;

public class cactus extends JApplet implements ActionListener {

Image s = getImage(getCodeBase(), "spin.jpg");
ImageIcon spin = new ImageIcon(s);

Random r = new Random();

Container contentArea;

String x = ("spin");

JButton FIRE = new JButton("spin");

JLabel slot11,slot12,slot13,slot21,slot22,slot23,slot31,slot32,slot33;

JLabel win = new JLabel("you have won congratz");

JLabel lose = new JLabel("hahahahahahahahahahaha you lose. GLaDos won. have a nice day =3");

Graphics g;

public void init() {
contentArea = getContentPane();
contentArea.setBackground(Color.PINK);
FlowLayout manager = new FlowLayout();
contentArea.setLayout(manager);
FIRE.addActionListener(this);
FIRE.setEnabled(true);
contentArea.add(FIRE);
setContentPane(contentArea);
}
public void actionPerformed(ActionEvent event) {
Image Lemon = getImage(getCodeBase(), "a.jpg");
ImageIcon pica = new ImageIcon(Lemon);
Image Cherry = getImage(getCodeBase(), "b.jpg");
ImageIcon picb = new ImageIcon(Lemon);
Image randomCelebrity = getImage(getCodeBase(), "c.jpg");
ImageIcon picc = new ImageIcon(randomCelebrity);

if(event.getSource()==FIRE) {
int random1 = r.nextInt(3)+1;
int random2 = r.nextInt(3)+1;
int random3 = r.nextInt(3)+1;

slot11 = new JLabel(pica);
slot12 = new JLabel(picb);
slot13 = new JLabel(picc);

slot21 = new JLabel(pica);
slot22 = new JLabel(picb);
slot23 = new JLabel(picc);

slot31 = new JLabel(pica);
slot32 = new JLabel(picb);
slot33 = new JLabel(picc);

contentArea.removeAll();
setContentPane(contentArea);

//random1
if(random1==1){
contentArea.add(slot11);
contentArea.add(FIRE);

setContentPane(contentArea);
}
if(random1==2){
contentArea.add(slot12);
contentArea.add(FIRE);
}
if(random1==3){
contentArea.add(slot13);
contentArea.add(FIRE);
}
//random2
if(random2==1){
contentArea.add(slot21);
contentArea.add(FIRE);

setContentPane(contentArea);
}
if(random2==2){
contentArea.add(slot22);
contentArea.add(FIRE);

setContentPane(contentArea);
}
if(random2==3){
contentArea.add(slot23);
contentArea.add(FIRE);

setContentPane(contentArea);
}
//random3
if(random3==1){
contentArea.add(slot31);
contentArea.add(FIRE);

setContentPane(contentArea);
}
if(random3==2){
contentArea.add(slot32);
contentArea.add(FIRE);

setContentPane(contentArea);
}
if(random3==3){
contentArea.add(slot33);
contentArea.add(FIRE);

setContentPane(contentArea);
}


if ((random1 == 1 && random2 == 1 && random3 == 1) ||
(random1 == 2 && random2 == 2 && random3 == 2) /*||
(random1 == 3 && random2 == 3 && random3 == 3))*/) {
win.setFont(new Font("wingdings2", Font.BOLD, 42));
win.setForeground(Color.red);
contentArea.remove(win);
contentArea.add(win);
setContentPane(contentArea);
}
else {
contentArea.add(lose);
setContentPane(contentArea);
}
}
}
}
Loved this place, still the best producers of power metal, and sparked my dreams of coding.

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: java giant button glitch
« Reply #1 on: May 26, 2011, 11:49:50 pm »
look into using layouts.