Results 1 to 3 of 3

Thread: Need help with small assignment pleaz...

  1. #1
    Join Date
    Jan 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Need help with small assignment pleaz...

    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:

    Code:
    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

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Of course it 'doesn't want to work': you've missed a whole bunch of closing braces.

    Hint: it would be easier to accept the parameters as actual command-line parameters (that's what I think of when someone says 'parameters to an application', anyway).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jan 2009
    Location
    Athens, GA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'm assuming you've got all import statements you need, thought it might be helpful to include them in the code snippet next time.

    I don't see any missing braces.

    I was able compile and run the program just fine. Of course it doesn't do anything yet. I assuming you've yet to complete the code for the actionPerformed method.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •