Hallo,
iemand een idee wat er fout loopt?
de kleur wordt bepaald in het frame ( door de switch )
maar wordt 1 seconde nadien overschreven door de standaard kleur
de code:
public class JKleur extends JFrame
{
public JKleur(String titel)
{
super(titel);
setup();
}
private void setup()
{
Dimension dimScreen = getToolkit().getScreenSize();
int w = dimScreen.width;
int h = dimScreen.height;
setSize(w/2, h/2);
setLocation(w/4, h/4);
}
public static void main(String args[])
{
JKleur app = new JKleur("Welkom bij de oefening op JFrame");
app.setVisible(true);
JOptionPane.showMessageDialog(null,"Welkom bij de oefening op JFrame ");
String titel = JOptionPane.showInputDialog(null, "Geef de titel in");
String kleur = JOptionPane.showInputDialog(null, "Geef nu de kleur in die u wenst\n1 = BLACK\n2 = BLUE\n3 = RED");
int k = Integer.parseInt(kleur);
JKleur app1 = new JKleur(titel);
switch(k)
{
case 1 : app1.setBackground(Color.black);
break;
case 2 : app1.setBackground(Color.blue);
break;
case 3 : app1.setBackground(Color.red);
break;
}
app1.setVisible(true);
app1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
iemand een idee wat er fout loopt?
de kleur wordt bepaald in het frame ( door de switch )
maar wordt 1 seconde nadien overschreven door de standaard kleur
de code:
public class JKleur extends JFrame
{
public JKleur(String titel)
{
super(titel);
setup();
}
private void setup()
{
Dimension dimScreen = getToolkit().getScreenSize();
int w = dimScreen.width;
int h = dimScreen.height;
setSize(w/2, h/2);
setLocation(w/4, h/4);
}
public static void main(String args[])
{
JKleur app = new JKleur("Welkom bij de oefening op JFrame");
app.setVisible(true);
JOptionPane.showMessageDialog(null,"Welkom bij de oefening op JFrame ");
String titel = JOptionPane.showInputDialog(null, "Geef de titel in");
String kleur = JOptionPane.showInputDialog(null, "Geef nu de kleur in die u wenst\n1 = BLACK\n2 = BLUE\n3 = RED");
int k = Integer.parseInt(kleur);
JKleur app1 = new JKleur(titel);
switch(k)
{
case 1 : app1.setBackground(Color.black);
break;
case 2 : app1.setBackground(Color.blue);
break;
case 3 : app1.setBackground(Color.red);
break;
}
app1.setVisible(true);
app1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}