Smirre
01-06-2009, 05:15 PM
Hi all,
I please need help with this question please:
"Write an application that draws an ellipse. It must accept two
parameters that are the sizes of the two axes in pixels.
Center the ellipse in the application"
Here is the code that I've tried so far:
public class EllipseApp extends JComponent implements ActionListener{
JFrame frame = new JFrame();
JTextField field1 = new JTextField("Width", 5);
JTextField field2 = new JTextField("Height", 5);
JButton button = new JButton("OK");
public EllipseApp() {
super();
frame.setTitle("Ellipse");
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
button.addActionListener(this);
JPanel pane = new JPanel();
pane.add(field1);
pane.add(field2);
pane.add(button);
frame.add(pane);
setVisible(true);
}
public void paintComponent(Graphics2D g, float a, float b) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
Ellipse2D.Float ellipse = new Ellipse2D.Float(0, 0, a, b);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.draw(ellipse);
g2.fill(ellipse);
g2.setColor(Color.blue);
}
public static void main(String[] args) {
EllipseApp e = new EllipseApp();
JPanel panel = new JPanel();
panel.add(e);
panel.setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
Object source = ae.getSource();
if (source == button) {
}
}
}
My program doesn't want to work and I do not know what to do further,
can anyone please help me with this,
I need your help.
Thanks in advance
I please need help with this question please:
"Write an application that draws an ellipse. It must accept two
parameters that are the sizes of the two axes in pixels.
Center the ellipse in the application"
Here is the code that I've tried so far:
public class EllipseApp extends JComponent implements ActionListener{
JFrame frame = new JFrame();
JTextField field1 = new JTextField("Width", 5);
JTextField field2 = new JTextField("Height", 5);
JButton button = new JButton("OK");
public EllipseApp() {
super();
frame.setTitle("Ellipse");
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
button.addActionListener(this);
JPanel pane = new JPanel();
pane.add(field1);
pane.add(field2);
pane.add(button);
frame.add(pane);
setVisible(true);
}
public void paintComponent(Graphics2D g, float a, float b) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
Ellipse2D.Float ellipse = new Ellipse2D.Float(0, 0, a, b);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.draw(ellipse);
g2.fill(ellipse);
g2.setColor(Color.blue);
}
public static void main(String[] args) {
EllipseApp e = new EllipseApp();
JPanel panel = new JPanel();
panel.add(e);
panel.setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
Object source = ae.getSource();
if (source == button) {
}
}
}
My program doesn't want to work and I do not know what to do further,
can anyone please help me with this,
I need your help.
Thanks in advance