标签:小代码
import java.awt.Frame; import java.awt.Point; import java.awt.image.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.imageio.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++; } }
这里面板菜单栏 还没有添加好 下一篇修改与运用
标签:小代码
原文地址:http://wzsts.blog.51cto.com/10251779/1795523