宿題スレPart56 874 (HPのソースをtxtに)


宿題スレPart56 >>874 (HPのソースをtxtに)

import java.awt.event.* ;
import javax.swing.* ;
import java.awt.Graphics ;
import java.awt.Color ;
	
public class GUISample0001 extends JPanel
                   implements MouseListener {
	final static Color bc = Color.white;  // 背景色
	final static Color dc = Color.green;  // 描画色
	private int[] posX;
	private int[] posY;
	private int count = 0;
	
	public GUISample0001() {
		posX = new int[5];
		posY = new int[5];
		addMouseListener(this);
		setBackground(bc);
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		for(int i = 0; i < posX.length-1; i++) {
			g.setColor(dc);
			g.drawLine(posX[i], posY[i], posX[i+1], posY[i+1]);
		}
	}
	
	public void mouseClicked(MouseEvent e) { }
	
	public void mouseEntered(MouseEvent e) { }
	
	public void mouseExited(MouseEvent e) { }
	
	public void mousePressed(MouseEvent e) {
		posX[count] = e.getX();
		posY[count] = e.getY();
		if(++count == 5) {
			count = 0;
			repaint();
		}
	}
	
	public void mouseReleased(MouseEvent e) { }
	
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.addWindowListener(new WindowAdapter() { 
			public void windowClosing(WindowEvent e) { System.exit(0); }
		});
		frame.getContentPane().add( new GUISample0001() );
		frame.setSize(640, 480);
		frame.setVisible(true);
	}
}

CONTENTS

最新の20件

2020-11-14 2005-12-06 2006-11-04 2012-07-15 2009-06-19 2011-03-03 2006-12-13 2007-11-05 2014-07-22 2014-07-19 2014-07-09 2014-01-14 2012-09-03 2012-03-28

今日の20件

人気の30件

  • counter: 2374
  • today: 1
  • yesterday: 0
  • online: 1