JFrame を拡張するメイン クラスがあり、それが jframe に jpanel を追加します。次に、jpanelの背景色を設定しようとしましたが、役に立ちませんでした。Googleで見つけたものによると、問題がどこにあるのかよくわかりsetBackground(Color)
ません.JPanelを設定するだけでこれを修正できますが、うまくいかないようです. setOpaque(true)
また、これに対する他の修正setVisible(true)
は、、、、または使用して JFrame を形成することgetContentPane().setBackground(Color)
でしたが、これらのどれも機能していないようです。より多くの情報が必要な場合、または他のアドバイスが必要な場合は、お気軽に教えてください。:) 主なクラスは次のとおりです。
public class main extends JFrame{
private Content content;
public main(){
content = new Content(400, 600);
this.setTitle("Shooter2.0");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.getContentPane().add(content);
this.getContentPane().setBackground(Color.BLACK);
this.pack();
this.setVisible(true);
try{
Thread.sleep(10000);
}catch(Exception e){}
}
public static void main(String[] args){
main game = new main();
}
}
Content クラスは次のとおりです。
public class Content extends JPanel{
private viewItem ship;
public Content(int w, int h){
this.setPreferredSize(new Dimension(w, h));
this.setLayout(new BorderLayout());
this.createBattlefield();
this.setOpaque(true);
this.setBackground(Color.BLACK);
this.repaint();
this.setVisible(true);
}
public void createBattlefield(){
ship = new viewItem("bubble-field.png", 180, 550, 40, 42);
}
public void paint(Graphics g){
g.setColor(Color.BLACK);
this.setBackground(Color.BLACK);
ship.draw(g);
}
}