Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By gimbal2

Thread: Help Me..!

  1. #1
    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0

    Unhappy ask a to put in the code..!

    Can anybody help me please..!


    I got a problem about to find a right code..!

    Help Me..!-circle.jpg


    So, when i have to click the red circle menu, a red circle object will come up.. And so on for the green and blue..!!

    I do really a support..!!!



    Here this the code :

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;

    public class Task
    {
    public static void main(String[] args)
    {
    // Frame
    JFrame frame = new JFrame("Menu");
    frame.setSize(300,300);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

    // menubar
    JMenuBar menubar = new JMenuBar();
    frame.setJMenuBar(menubar);

    // File
    JMenu file = new JMenu("File");
    menubar.add(file);
    // Exit
    JMenuItem exit = new JMenuItem("Exit");
    file.add(exit);
    exit.addActionListener(new exitApp());



    // Circle
    JMenu circle= new JMenu("Circle");
    menubar.add(circle);

    // Buat Menu Item About
    JMenuItem bulat_merah = new JMenuItem("Red Circle");
    circle.add(red_circle);


    JMenuItem bulat_hijau = new JMenuItem("Green Circle");
    circle.add(green_circle);

    JMenuItem bulat_biru = new JMenuItem("Blue Circle");
    circle.add(blue_circle);


    frame.setVisible(true);
    }

    // EXIT
    static class exitApp implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    System.exit(0);
    }
    }

    }
    Last edited by jefri desrosiers; 07-17-2013 at 01:10 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Help Me..!

    Quote Originally Posted by jefri desrosiers View Post
    Help Me..!
    Please go through the Forum Rules, particularly the third paragraph. Then go through the Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly. To change the subject line, click 'Edit Post' and then 'Go Advanced'

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,367
    Rep Power
    6

    Default Re: Help Me..!

    You are not going to get any code, just ideas for you to investigate yourself. There are always multiple solutions to go about this. You could create circle images in some paint program and simply put an imageicon with the correct image.

    Another way is to draw the circle yourself in the code - this is called "custom painting". You will want to add a JPanel to your JFrame and on this JPanel you can do custom painting.

    Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)

  4. #4
    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0

    Default Re: Help Me..!

    To Gimbal2 here is the code to make red circle..

    public class DrawOval extends JFrame
    {
    public DrawOval ()
    {
    super ("Gambar Oval");
    setSize (600,365);
    setVisible(true);
    }


    public void paint (Graphics g)
    {
    super.paint (g);
    g.setColor (Color.RED);
    g.fillOval (120,130,200,200);
    // g.fillOval(100,40,90,50);

    }

    public static void main (String args [])
    {
    DrawOval test = new DrawOval ();
    test.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

    }
    }

    I don't know to put red circle code into the menu bar code..

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Help Me..!

    Kindly go through the links I posted at #2.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,367
    Rep Power
    6

    Default Re: Help Me..!

    Quote Originally Posted by jefri desrosiers View Post
    I don't know to put red circle code into the menu bar code..
    So? Learn. Research. Not knowing is not a problem.
    noobplus likes this.

  7. #7
    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0

    Default Re: Help Me..!

    Oh please gimbal2, i'm totally as a beginner and i have been sped a lot of time but does not got something like what i need..!!

    PLEASE WOULD YOU TO HELP ME.

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: Help Me..!

    Your DrawOval object is an extension of a JFrame, so you're trying to paint/draw in a JFrame; it won't work and the tutorials tell you why it won't work. You should extend a, say, JPanel and paint/draw on that and add that extension of a JPanel to the content pane to your DrawOval object. Oh, and don't override the paint( ... ) method; override the paintComponent( ... ) method instead. But first start reading those tutorials and don't just guess.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Help Me..!

    You aren't helping your cause by not bothering to go through the links members have posted.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Posting Permissions

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