Java Netbeans绘制组件
在面板上画点的方向正确吗?一切都很好,但我不知道这是否是一个正确的方式来画东西Java Netbeans绘制组件,java,swing,drawing,paintcomponent,Java,Swing,Drawing,Paintcomponent,在面板上画点的方向正确吗?一切都很好,但我不知道这是否是一个正确的方式来画东西 public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; Dimension size = getSize(); g2d.setColor(Color.red); for(int i=0;i<last;i++) { i
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
Dimension size = getSize();
g2d.setColor(Color.red);
for(int i=0;i<last;i++) {
int x = i*(800/last);
int y = one[i];
g2d.drawLine(x, y, x, y);
}
public static void main(String[] args)throws Exception {
progr progr= new progr();
JFrame frame = new JFrame("Points");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 500);
frame.add(new progr());
frame.setVisible(true);
}
公共组件(图形g){
超级组件(g);
Graphics2D g2d=(Graphics2D)g;
维度大小=getSize();
g2d.setColor(Color.red);
对于(int i=0;我也要查看,并编辑您的问题,以包括显示您的方法的。是的,重写paintComponent()
并调用super.paintComponent())
是定制绘画的正确方法。我不知道你的绘画代码应该做什么,因为你没有发布SSCCE,所以我不知道是否有更好的方法来完成你想要的。