Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计 » Swing  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:[求助]Graphics2D 类中的对象可以加监听事件吗? [Re:kavinwang]
redsuner





发贴: 9
积分: 0
于 2004-10-29 10:38 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
package java2ddemo;

import java.awt.*;
import java.awt.geom.*;
import java.awt.geom.Ellipse2D;
import java.awt.event.*;
import javax.swing.*;

public class Java2DFrame extends JFrame{
JPanel contentPane;
GeneralPath rect = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
JButton jButton1 = new JButton();

//Construct the frame
public Java2DFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public void paint(Graphics g){
Graphics2D g2d = (Graphics2D)g;
g2d.setColor(Color.cyan);
rect.moveTo(20,20);
rect.lineTo(120,20);
rect.lineTo(120,20);
rect.lineTo(120,60);
rect.lineTo(20,60);
rect.closePath();
g2d.fill(rect);
g2d.setColor(Color.blue);
Ellipse2D ellipse = new Ellipse2D.Float(100,100,300,300);
//g2d.fill(ellipse);
//g2d.draw(ellipse);
MyEllipse ell2 = new MyEllipse(100,100,300,300);
g2d.fill(ell2);
g2d.draw(ell2);
ell2.addMouseListener(new MyEllipseListener());

}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
jButton1.setBounds(new Rectangle(177, 147, 71, 33));
jButton1.setText("jButton1");
contentPane.setLayout(null);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
contentPane.add(jButton1, null);
ActionListener listener = new C2DListener();

}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEventEnvelope;
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
class C2DListener implements ActionListener {
public void actionPerformed(ActionEvent e){
if(e.getSource() == "rect"){
System.out.println("2D recall sucessful!");
}
if(e.getSource() == "jButton1"){
System.out.println("Button recall sucessful!");
}

}

}
class MyEllipse extends Ellipse2D.Float{
public MyEllipse(float x1,float x2,float y1,float y2){
super(x1,x2,y1,y2);
}
public MyEllipse createEllipse(float x1,float x2,float y1,float y2){
Ellipse2D ell = new Ellipse2D.Float(x1,x2,y1,y2);
return (MyEllipse)ell;

}
public void addMouseListener(MouseListener listener){

}
}
class MyEllipseListener implements MouseListener{
public void mouseClicked(MouseEvent e){
System.out.println("Button recall sucessful!");

}

public void mouseEntered(MouseEvent e) {

}

public void mousePressed(MouseEvent e) {
System.out.println("Button recall sucessful!");

}

public void mouseExited(MouseEvent e) {

}
public void mouseReleased(MouseEvent e) {

}

}




话题树型展开
人气 标题 作者 字数 发贴时间
8756 [求助]Graphics2D 类中的对象可以加监听事件吗? redsuner 41 2004-10-27 11:19
7674 Re:[求助]Graphics2D 类中的对象可以加监听事件吗? kavinwang 31 2004-10-27 11:20
7763 Re:[求助]Graphics2D 类中的对象可以加监听事件吗? redsuner 83 2004-10-29 11:25
7586 Re:[求助]Graphics2D 类中的对象可以加监听事件吗? redsuner 399 2004-10-27 11:30
7641 Re:[求助]Graphics2D 类中的对象可以加监听事件吗? kavinwang 77 2004-10-27 11:38
7516 Re:[求助]Graphics2D 类中的对象可以加监听事件吗? redsuner 11 2004-10-27 11:41
7510 Re:[求助]Graphics2D 类中的对象可以加监听事件吗? redsuner 7 2004-10-28 11:00
7581 Re:[求助]Graphics2D 类中的对象可以加监听事件吗? kavinwang 63 2004-10-28 11:01
7673 Re:[求助]Graphics2D 类中的对象可以加监听事件吗? redsuner 3054 2004-10-29 10:38
7692 Re:[求助]Graphics2D 类中的对象可以加监听事件吗? kavinwang 567 2004-10-29 10:52
7603 Re:[求助]Graphics2D 类中的对象可以加监听事件吗? redsuner 117 2004-10-29 11:00
7559 Re:[求助]Graphics2D 类中的对象可以加监听事件吗? redsuner 12 2004-10-29 11:02
7698 Re:[求助]Graphics2D 类中的对象可以加监听事件吗? kavinwang 266 2004-10-29 11:10

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923