Blame view

JPAINT/jpaint/TextDialog.java 2.58 KB
933d00ad   rlentieu   add JPaint
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  import java.awt.event.ActionEvent;

  import java.awt.event.ActionListener;

  import javax.swing.JButton;

  import javax.swing.JDialog;

  import javax.swing.JLabel;

  import javax.swing.JTextField;

  import java.awt.Graphics;

  import java.awt.Frame;

  

  /**

   * A TextDialog is created where you can input a string and there is an advanced

   * setting method. Once you submit you draw the string onto the screen.

   **/

  public class TextDialog extends JDialog implements ActionListener

  {

  	private JButton submit, advanced;

  	private JTextField text, xCoord, yCoord;

  	private JLabel x, y;

  	private FontChooser adText;

  	

  	/** Creates a TextDialog with parameters of the x and y coordinates clicked. **/

  	public TextDialog(int xValue, int yValue)

  	{

  		// sets the title and other default settings

  		setTitle("Text Setup");

  		getContentPane().setLayout(null);

  		setSize(160,200);

  		setVisible(true);	

  		initialize(xValue,yValue);

  	}

  	/** 

  	 * Instantiates the fields for the text dialog, such as the text field,

  	 * the x and y coordinate field and the advanced settings.

  	 **/

  	public void initialize(int xValue, int yValue)

  	{

  		x = new JLabel("X: ");

  		x.setBounds(20,50,20,20);

  		getContentPane().add(x);

  		

  		y = new JLabel("Y: ");

  		y.setBounds(20,80,20,20);

  		getContentPane().add(y);

  		

  		text = new JTextField();

  		text.setBounds(20,20,120,20);

  		getContentPane().add(text);

  		

  		xCoord = new JTextField(xValue+"");

  		xCoord.setBounds(40,50,100,20);

  		getContentPane().add(xCoord);

  		

  		yCoord = new JTextField(yValue+"");

  		yCoord.setBounds(40,80,100,20);

  		getContentPane().add(yCoord);

  		

  		submit = new JButton("SUBMIT");

  		submit.setBounds(20,110,120,20);	

  		getContentPane().add(submit);

  		submit.addActionListener(this);

  		

  		advanced = new JButton("Advanced");

  		advanced.setBounds(20,140,120,20);	

  		getContentPane().add(advanced);

  		advanced.addActionListener(this);

  		

  		Frame[] frames = ControlClass.getFrames();

  		adText = new FontChooser(frames[0]);

  	}

  	

  	/** 

  	 * Invoked if action performed. If the button clicked is submit then it

  	 * will draw it to the screen other wise if its the advanced button then 

  	 * the advanced settings will pop up. 

  	 **/

  	public void actionPerformed(ActionEvent e)

  	{

  		JButton hit = (JButton)e.getSource();

  		if(hit == submit)

  		{

  			((DrawingCanvas)ControlClass.canvas.get(ControlClass.currentFile)).textOperation2(text.getText(),

  			Integer.parseInt(xCoord.getText()),Integer.parseInt(yCoord.getText()), adText.getSelectedFont());

  			setVisible(false);

  		}

  		if(hit == advanced)

  		{

  			adText.setVisible(true);

  		}

  	}

  }