packagecom.fzhw.app;
importjava.awt.BorderLayout;
importjava.awt.Graphics;
importjava.awt.Graphics2D;
importjava.awt.HeadlessException;
importjavax.swing.JFrame;
importjavax.swing.JPanel;
publicclassXiangqiextendsJFrame{
privatestaticfinallongserialVersionUID=1;
publicXiangqi()throwsHeadlessException{
super();
setTitle(myboard);
this.getContentPane().setLayout(newBorderLayout());
this.getContentPane().add(newBoard(),BorderLayout.CENTER);
this.setSize(960,960);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
publicstaticvoidmain(Stringargs[]){
newXiangqi().setVisible(true);
}
}
classBoardextendsJPanel{
privatestaticfinallongserialVersionUID=1L;
protectedvoidpaintComponent(Graphicsg){
super.paintComponent(g);
Graphics2Dg2d=(Graphics2D)g;
intwidth=this.getWidth();
intheight=this.getHeight();
inthGap=height/9;
intwGap=width/8;
for(inti=0;i<10;i++){
g2d.drawLine(0,i*hGap,width,i*hGap);
}
for(inti=0;i<9;i++){
g2d.drawLine(i*wGap,0,i*wGap,4*hGap);
g2d.drawLine(i*wGap,5*hGap,i*wGap,height);
}
g2d.drawString(楚河汉界,width/2,height/2);
g2d.drawLine(3*wGap,0,5*wGap,2*hGap);
g2d.drawLine(5*wGap,0,3*wGap,2*hGap);
g2d.drawLine(3*wGap,height,5*wGap,height-2*hGap);
g2d.drawLine(3*wGap,height-2*hGap,5*wGap,height);
g2d.dispose();
}
}
两种选择第一,你用一个背景图片来充当欺骗,落子位置的在panel上转化,楚河汉界不用管,两边是对称的。
第二种用Graphics2D自己drawline。
我给你写好了,但是10分太少,不想给啊