package javagame.test;//不同包下的另外一个类,包含主函数import javax.swing.JOptionPane;import com.sun.prism.Graphics;import javagame.frame.MyChessFrame;public class Initail { public static void main(String[] args) { // TODO Auto-generated method stub MyChessFrame jf=new MyChessFrame(); }}package javagame.frame;import java.awt.*;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;import javax.swing.JFrame;import javax.swing.JOptionPane;import javax.swing.JPopupMenu;import com.sun.prism.Graphics;public class MyChessFrame extends JFrame implements MouseListener{ BufferedImage bgImage=null; public MyChessFrame() { this.setTitle("三炮十五兵"); this.setSize(526, 526); this.setResizable(false); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); int width=Toolkit.getDefaultToolkit().getScreenSize().width; int height=Toolkit.getDefaultToolkit().getScreenSize().height; this.setLocation((width-526)/2,(height-526)/2); try{ bgImage=ImageIO.read(new File("C:/Users/imdreamer/Desktop/bg.png")); }catch(IOException e) { e.printStackTrace(); } this.addMouseListener(this); this.setVisible(true); } public void paint(Graphics g) { g.drawLine(22, 33, 22,77); g.drawLine(22, 11, 22, 55); }
1 回答
慕少森
TA贡献2019条经验 获得超9个赞
Graphics 引用不正确,应该是java.awt.Graphics
paint中,只有
g.drawLine(22, 33, 22,77);
g.drawLine(22, 11, 22, 55);
颜色又没改变了,使用默认色。就算画出来了,也看不见了。
添加回答
举报
0/150
提交
取消