【发布时间】:2016-04-24 04:31:06
【问题描述】:
我正在尝试用 Java 编写此代码来开始创建游戏。尽管我在代码中使用了 setBackgroundColor,但默认情况下仍保留的背景颜色存在问题。有人可以告诉我如何解决这个问题吗?是我的代码:
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);
}}
【问题讨论】:
-
@A. Di Matteo 标题有什么问题?这就是我想给它命名的方式。
-
这很奇怪,我只是添加了标签,我没有更改标题,你可以恢复它,绝对。然而,作为我编辑的一部分,历史指出了变化,非常奇怪的行为
-
好的!只是认为这是像我一样命名标题的问题。认为这是一个编码问题。好的,谢谢
标签: java swing colors awt background-color