当前位置: 技术问答>java相关
绘ArrayList()中的直线
来源: 互联网 发布时间:2017-04-11
本文导语: 本程序要实现用上,下,左,右,四键绘直线,直线保存在ArrayList()中,但实际执行中并没有画出直线 import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.util.*; class KeyGame { public static ...
本程序要实现用上,下,左,右,四键绘直线,直线保存在ArrayList()中,但实际执行中并没有画出直线
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
class KeyGame
{
public static void main(String[] ags)
{
KeyGameFrame frame = new KeyGameFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class KeyGameFrame extends JFrame
{
public KeyGameFrame()
{
setTitle("KeyGame");
setSize(WIDTH, HEIGHT);
KeyPanel panel = new KeyPanel();
Container contentpane = getContentPane();
contentpane.add(panel);
}
public static final int WIDTH = 350;
public static final int HEIGHT = 400;
}
class KeyPanel extends JPanel
{
public KeyPanel()
{
last = new Point2D.Double(100, 100);
lines = new ArrayList();
KeyHandler listener = new KeyHandler();
addKeyListener(listener);
}
public void paintComponents(Graphics g)
{
super.paintComponents(g);
Graphics2D g2 = (Graphics2D) g;
System.out.println("OK");//此语句好象并没被调用,但
add中有repaint()函数啊
for (int i=0; i
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
class KeyGame
{
public static void main(String[] ags)
{
KeyGameFrame frame = new KeyGameFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class KeyGameFrame extends JFrame
{
public KeyGameFrame()
{
setTitle("KeyGame");
setSize(WIDTH, HEIGHT);
KeyPanel panel = new KeyPanel();
Container contentpane = getContentPane();
contentpane.add(panel);
}
public static final int WIDTH = 350;
public static final int HEIGHT = 400;
}
class KeyPanel extends JPanel
{
public KeyPanel()
{
last = new Point2D.Double(100, 100);
lines = new ArrayList();
KeyHandler listener = new KeyHandler();
addKeyListener(listener);
}
public void paintComponents(Graphics g)
{
super.paintComponents(g);
Graphics2D g2 = (Graphics2D) g;
System.out.println("OK");//此语句好象并没被调用,但
add中有repaint()函数啊
for (int i=0; i
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!