+ -
当前位置:首页 → 问答吧 → 2d画图

2d画图

时间:2011-11-07

来源:互联网

不好意思:

小的意思是这样的... 因为书上/网路上看到的都是长这样的

画图:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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:
不好意思:

小的意思是这样的... 因为书上/网路上看到的都是长这样的

画图:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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