[英]Is there any way that I can get a parameter in paintComponent?
我在paintComponent
方法中如何設置其他參數時遇到問題。
我還沒有找到其他方法。
import javax.swing.*;
import java.awt.*;
public class Interface extends JPanel
{
protected void paintComponent(Graphics g *here(not part of code btw)*) {
super.paintComponent(g);
g.setColor(Color.orange);
g.fillRect(0, 0, 100, 100);
}
public void CreateWindow(String name, int Xsize, int Ysize) {
//laver et JFrame og klader det "frame" !
JFrame frame= new JFrame();
frame.setTitle(name);
frame.setSize(Xsize, Ysize);
frame.setLocation(200, 200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
Interface JPanel = new Interface();
frame.add(JPanel);
Graphics Grafik = getGraphics();
paintComponent(Grafik);
}
}
當我使用參數運行代碼時,它不會繪制矩形。
但是,如果只有Graphics
參數,它將運行良好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.