import java.awt.Frame; import java.awt.Point; import java.awt.p_w_picpath.BufferedImage; import java.lang.reflect.Field; import java.util.List; import java.awt.Button; import java.awt.Color; import java.awt.Dimension; import java.awt.Frame; import java.awt.Graphics; import java.awt.Menu; import java.awt.MenuBar; import java.awt.MenuItem; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.util.ArrayList; import java.util.Date; import java.util.Timer; import java.util.TimerTask; import javax.p_w_picpathio.ImageIO; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JPanel; import javax.swing.JTextArea; import java.awt.Graphics; import java.awt.Point; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Date; import java.util.Timer; import java.util.TimerTask; import javax.swing.JFrame; import javax.swing.JPanel; public class Main extends JPanel { static int a = 1; static Point p = null; static int count=0; public static Frame frame = new Frame(); public static void main(String[] args) { Main f = new Main(); frame.setTitle("【點三下】"); frame.add(f); frame.setSize(500, 500); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); //frame. MenuBar bar = new MenuBar(); Menu CD = new Menu("【菜單】"); MenuItem m = new MenuItem("【介紹】"); MenuItem n = new MenuItem ("【版本】"); bar.add(CD); CD.add(m); CD.add(n); f.Action(); frame.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { int x = e.getX(); int y = e.getY(); count++; if(count==3) { frame.add(new Button("you had pass")); } p = new Point(x, y); //else frame.repaint(); } }); frame.setVisible(true); } private Timer timer; private void Action() { // ListenerClick(); timer = new Timer(); timer.schedule(new TimerTask() { public void run() { frame.repaint(); } }, new Date(), 1000); } @Override public void paint(Graphics g) { g.drawLine(30,30,30,300); // 左邊 g.drawLine(30,30,300,30); // 上邊 g.drawLine(300,30,300,300);// 右邊 g.drawLine(30,300,300,300);// 下邊 g.drawString("【點三下】",333,33); g.drawString("框內點三下",333,50); if (p != null) { if(30<p.getX()&&p.getX()<300&&30<p.getY()&&p.getY()<300) { g.drawString(p.getX() + " " + p.getY(),(int)p.getY(),(int)p.getY()); g.drawString("X = "+p.getX(),333,70); g.drawString("Y = "+p.getY(),333,90); } else { g.drawString("【error】",44,344); g.drawString("X = "+p.getX(),44,360); g.drawString("Y = "+p.getY(),44,390); } } g.drawString("我會一直打印時間 "+a+"s", 100, 100); a++; } }
這裏面板菜單欄 尚未添加好 下一篇修改與運用java