【发布时间】:2018-03-19 05:31:51
【问题描述】:
我觉得我已经完成了我需要做的所有事情:
- 创建一个图形类,它有一个名为paintComponent 的void 并扩展了JComponent
- 让paintComponent void有Graphics g作为参数,然后做Graphics2D g2d = (Graphics2D) g;
- 将 Graphics 类添加到我的 JFrame
我找不到任何问题,所以我有点困惑。
我的代码在这里:
public static void main(String[] args) {
DragonEscape game = new DragonEscape();
frame.setTitle(title);
frame.setSize(1000, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.add(new Graphicsa());
frame.add(game);
}
和
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;
public class Graphicsa extends JComponent {
private static final long serialVersionUID = 1L;
public Graphics g;
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g.fillRect(0, 0, 1000, 500);
g.setColor(Color.gray);
g.fillRect(0, 0, 100, 100);
}
}
【问题讨论】:
-
有人会做点什么吗
-
(1-) 耐心等待!人们在有时间的时候回答问题。不能保证什么时候会。
-
@camickr 好的。我会
标签: java swing graphics jframe