这个程序为什么出错???

teddywtd 2003-05-17 11:18:51
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class PaintTest extends JFrame {
private int pointCount = 0;
private Point points[] = new Point[ 1000 ];
private JList colorList;
private Container container;
int currentColor ;
private final String colorNames[] = { "Black", "Blue", "Cyan",
"Dark Gray", "Gray", "Green", "Light Gray", "Magenta",
"Orange", "Pink", "Red", "White", "Yellow" };
private final Color colors[] = { Color.black, Color.blue, Color.cyan,
Color.darkGray, Color.gray, Color.green, Color.lightGray, Color.magenta,
Color.orange, Color.pink, Color.red, Color.white, Color.yellow };
public PaintTest()
{
super( "My simple PaintTest program" );
container = getContentPane();
container.setLayout( new FlowLayout() );
colorList = new JList( colorNames );
colorList.setVisibleRowCount( 5 );
colorList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
container.add( new JScrollPane( colorList ) );
colorList.addListSelectionListener( new ListSelectionListener()
{ public void valueChanged( ListSelectionEvent event )
{
//currentColor=colors[colorList.getSelectedIndex()];
}
}
);
addMouseMotionListener( new MouseMotionAdapter()
{
public void mouseDragged( MouseEvent event )
{ if ( pointCount < points.length )
{ points[ pointCount ] = event.getPoint();
++pointCount;
repaint(); } } }
);
setSize( 300, 150 );
setVisible( true );
}
public void paint( Graphics g )
{ super.paint( g );
g.setColor(colors[1]);
for ( int i = 0; i < points.length && points[ i ] != null; i++ )
g.fillOval( points[ i ].x, points[ i ].y, 4, 4 );

}
public static void main( String args[] )
{
PaintTest application = new PaintTest();
application.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
application.addWindowListener( new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0); }
});
}
}
...全文
64 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
mendynew 2003-05-18
  • 打赏
  • 举报
回复
我觉得也是这样
CyberH 2003-05-17
  • 打赏
  • 举报
回复
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;

public class Second extends JFrame {
private int pointCount = 0;
private Point points[] = new Point[ 1000 ];
private JList colorList;
private Container container;
int currentColor ;
private final String colorNames[] = { "Black", "Blue", "Cyan",
"Dark Gray", "Gray", "Green", "Light Gray", "Magenta",
"Orange", "Pink", "Red", "White", "Yellow" };
private final Color colors[] = { Color.black, Color.blue, Color.cyan,
Color.darkGray, Color.gray, Color.green, Color.lightGray, Color.magenta,
Color.orange, Color.pink, Color.red, Color.white, Color.yellow };
public Second()
{
super( "My simple Second program" );
container = getContentPane();
container.setLayout( new FlowLayout() );
colorList = new JList( colorNames );
colorList.setVisibleRowCount( 5 );
colorList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
container.add( new JScrollPane( colorList ) );
colorList.addListSelectionListener( new CLI());

addMouseMotionListener( new MouseMotionAdapter()
{
public void mouseDragged( MouseEvent event )
{ if ( pointCount < points.length )
{ points[ pointCount ] = event.getPoint();
++pointCount;
repaint(); } } }
);
setSize( 300, 150 );
setVisible( true );
}
public void paint( Graphics g )
{ super.paint( g );
g.setColor(colors[1]);
for ( int i = 0; i < points.length && points[ i ] != null; i++ )
g.fillOval( points[ i ].x, points[ i ].y, 4, 4 );

}
public static void main( String args[] )
{
Second application = new Second();
application.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
application.addWindowListener( new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0); }
});
}
class CLI implements ListSelectionListener {
public void valueChanged( ListSelectionEvent event )
{
//currentColor=colors[colorList.getSelectedIndex()];
}
}
}
jsyx 2003-05-17
  • 打赏
  • 举报
回复
加一句
import javax.swing.event.*;

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧