2d画图
时间:2011-11-07
来源:互联网
不好意思:
小的意思是这样的... 因为书上/网路上看到的都是长这样的
画图:
简单来说 就是画图的method: paintComponent()
一定要放在继承JPanel的class里面 才能划划
------------------------------------------------------------
*我不想要让GUI一形成 就画画 也才能画画
***我想要直接call "一个画图method(我自己建一个class 写一个method ), 去画出我所要的图形" ***
每当我需要画画时. 在我需要的时候才划,可以把JPanel 画板类的这些东西 当助参数来pass
比方说今天导入了一张相片 我想在上面划一个大圆形
有没有类似的api 行为像是: draw( ??, JPanel ) 然后draw里面的implementation 去对JPanel 作画
找了真的很久 请高手帮忙
小的意思是这样的... 因为书上/网路上看到的都是长这样的
画图:
1 |
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class InputDialog2 { public static void main(String[] args) { InputDialog2Frame f=new InputDialog2Frame(); f.setVisible(true); } } class InputDialog2Frame extends JFrame { InputDialog2Frame() { super( "InputDialog2 "); setDefaultCloseOperation(EXIT_ON_CLOSE); setLocation(400,300); setSize(300,200); ButtonPane p=new ButtonPane(); Container c=getContentPane(); c.add(p); } } class ButtonPane extends JPanel { String input= " "; ButtonPane() { JButton click=new JButton( "click me "); add(click); click.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { input=JOptionPane.showInputDialog(this, "Please input something "); repaint(); } }); } protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawString(input, 50,100); } } |
简单来说 就是画图的method: paintComponent()
一定要放在继承JPanel的class里面 才能划划
------------------------------------------------------------
*我不想要让GUI一形成 就画画 也才能画画
***我想要直接call "一个画图method(我自己建一个class 写一个method ), 去画出我所要的图形" ***
每当我需要画画时. 在我需要的时候才划,可以把JPanel 画板类的这些东西 当助参数来pass
比方说今天导入了一张相片 我想在上面划一个大圆形
有没有类似的api 行为像是: draw( ??, JPanel ) 然后draw里面的implementation 去对JPanel 作画
找了真的很久 请高手帮忙
作者: msn_413413 发布时间: 2011-11-07
msn_413413 wrote:
不好意思:
小的意思是这样的... 因为书上/网路上看到的都是长这样的
画图:
简单来说 就是画图的method: paintComponent()
一定要放在继承JPanel的class里面 才能划划
------------------------------------------------------------
*我不想要让GUI一形成 就画画 也才能画画
***我想要直接call "一个画图method(我自己建一个class 写一个method ), 去画出我所要的图形" ***
每当我需要画画时. 在我需要的时候才划,可以把JPanel 画板类的这些东西 当助参数来pass
比方说今天导入了一张相片 我想在上面划一个大圆形
有没有类似的api 行为像是: draw( ??, JPanel ) 然后draw里面的implementation 去对JPanel 作画
找了真的很久 请高手帮忙
Displayable UI component 有提供一个可用来绘图於 component 之上的 Graphics object
不好意思:
小的意思是这样的... 因为书上/网路上看到的都是长这样的
画图:
1 |
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class InputDialog2 { public static void main(String[] args) { InputDialog2Frame f=new InputDialog2Frame(); f.setVisible(true); } } class InputDialog2Frame extends JFrame { InputDialog2Frame() { super( "InputDialog2 "); setDefaultCloseOperation(EXIT_ON_CLOSE); setLocation(400,300); setSize(300,200); ButtonPane p=new ButtonPane(); Container c=getContentPane(); c.add(p); } } class ButtonPane extends JPanel { String input= " "; ButtonPane() { JButton click=new JButton( "click me "); add(click); click.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { input=JOptionPane.showInputDialog(this, "Please input something "); repaint(); } }); } protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawString(input, 50,100); } } |
简单来说 就是画图的method: paintComponent()
一定要放在继承JPanel的class里面 才能划划
------------------------------------------------------------
*我不想要让GUI一形成 就画画 也才能画画
***我想要直接call "一个画图method(我自己建一个class 写一个method ), 去画出我所要的图形" ***
每当我需要画画时. 在我需要的时候才划,可以把JPanel 画板类的这些东西 当助参数来pass
比方说今天导入了一张相片 我想在上面划一个大圆形
有没有类似的api 行为像是: draw( ??, JPanel ) 然后draw里面的implementation 去对JPanel 作画
找了真的很久 请高手帮忙
Displayable UI component 有提供一个可用来绘图於 component 之上的 Graphics object
作者: Duncan 发布时间: 2011-11-07
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28