So i made a face using several ovals, a arc, and a polyline in the graphics class. I want to be able to change the size of the face based on the number input into the JTextField. Right now the value for the textfield is the variable "size" in the drawface method. Any idea on how I could get the entire face (all of the drawn objects that its made of) to be resized to scale. Heres my code...
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
@SuppressWarnings("serial")
public class Ex1 extends JFrame implements FocusListener {
/**
* @param args
*/
public void focusGained(FocusEvent e)
{
if(e.getSource() == data)
{data.setText("");
}}
public void focusLost(FocusEvent e)
{
}
private JTextField data;
private JButton go;
public Ex1(int size) {
super("Face Drawing Program");
setSize(750, 750);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
data = new JTextField("size of face?");
data.addFocusListener(this);
go = new JButton("draw it");
go.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
makeFace(new Integer(data.getText()));
}
});
Container myPane = getContentPane();
myPane.setLayout(new FlowLayout());
myPane.add(go);
myPane.add(data);
validate();
}
public void makeFace(int size) {
Graphics g = getGraphics();
//draw face
g.drawOval(265,275,275,275);
//draw left eye, right eye, nose and mouth, respectively
g.drawOval(320,365,60,35);
g.drawOval(430,365,60,35);
int[] xArray = {410, 380, 410};
int[] yArray = {425, 450, 450};
g.drawPolyline(xArray, yArray, 3);
g.drawArc(360, 475, 100, 25, 180, 180);
}
public static void main(String[] args) {
new Ex1(400);
}
}