I'm trying this code in Java to start creating a game.I have a problem with the background color which stays by default even though I've used setBackgroundColor into the code.Can someone show me how to fix this?This is my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.*;
import java.util.Random;
public class Background extends JFrame{
private JButton b;
public Background () {
super("the title");
setLayout(new FlowLayout());
b=new JButton("ROLL THE DICES");
b.setForeground(Color.WHITE);//ndryshon ngjyren e shkrimit
b.setBackground(Color.YELLOW);
b.setBounds(20, 30, 20, 70);
add(b);
thehandler hand=new thehandler();
b.addActionListener(hand);
}
private class thehandler implements ActionListener{
public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(null, "Ju shtypet butonin");
}
}
public static void main(String[] args) {
Background f=new Background();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setBackground(Color.GREEN);
f.setSize(400,300);
f.setVisible(true);
}}