Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Please anyone can you fix my Code??

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please anyone can you fix my Code??

    Hey kindly correct my mistakes please... if you cannot...
    can you please forward me to the person / forum that can guide me and help me!?

     
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.io.IOException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import MyTrials.Pixel;
     
    public class MyFrame extends JFrame{
     
        public static Pixel point = new Pixel();
        public JPanel panel1;
        public JCheckBox face;
        public JCheckBox head;
        public JCheckBox tail;
        public JCheckBox body;
        public JPanel panel2;
        public JButton left;
        public JButton right;
        public JButton reset;
        public JButton load;
        public JButton save;
     
        public MyFrame(){
            setTitle("FrameButtonTrials");
            setSize(600, 250);
            setVisible(true);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
        }
        public void addpanel1(){
            panel1 = new JPanel();
            getContentPane().add(panel1, "West");
            panel1.setLayout(new GridLayout(5, 1));
            face = new JCheckBox("String");
            tail = new JCheckBox("Line");
            head = new JCheckBox("Circle");
            body = new JCheckBox("Rectangle");
            panel1.add(face);
            panel1.add(tail);
            panel1.add(head);
            panel1.add(body);
            face.addItemListener(new CkeckBoxWatcher());
            tail.addItemListener(new CkeckBoxWatcher());
            head.addItemListener(new CkeckBoxWatcher());
            body.addItemListener(new CkeckBoxWatcher());
        }
        public void addpanel2(){
            panel2 = new JPanel();
            getContentPane().add(panel2, "South");
            panel2.setLayout(new GridLayout(2, 3));
            left = new JButton("<< Move left");
            right = new JButton("Move right >>");
            reset = new JButton("Reset coordinates");
            load = new JButton("Load last saved coordinates");
            save = new JButton("Save coordinates");
            panel2.add(left);
            panel2.add(right);
            panel2.add(reset);
            panel2.add(load);
            panel2.add(save);
            left.addActionListener(new ButtonWatcher());
            right.addActionListener(new ButtonWatcher());
            save.addActionListener(new ButtonWatcher());
            reset.addActionListener(new ButtonWatcher());
            load.addActionListener(new ButtonWatcher());
        }
     
        public void paint(Graphics g)
        {
          super.paint(g);
          g.drawRect(140, 40, 440, 140);
          g.setColor(Color.white);
          g.fill3DRect(140, 40, 440, 140, true);
     
          if (head.isSelected())
          {
            g.drawOval(point.x + 92, 70, 60, 40);
            g.setColor(Color.red);
            g.fillOval(point.x + 92, 70, 60, 40);
          }
          if (tail.isSelected())
          {
            g.drawLine(point.x, point.y, 150, 70);
            g.setColor(Color.red);
          }
          if (body.isSelected())
          {
            g.drawRect(point.x - 5, 100, 100, 50);
            g.setColor(Color.red);
            g.fill3DRect(point.x - 5, 100, 100, 50, true);
          }
          if (face.isSelected())
          {
            Font font = new Font("Sherif", Font.BOLD, 21);
            g.setFont(font);
            g.setColor(Color.black);
            g.drawString("*   --", point.x + 111, 100);
          }
        }
        public class CkeckBoxWatcher implements ItemListener{
          public void itemStateChanged(ItemEvent i){
             repaint();
          }
        }
        private class ButtonWatcher implements ActionListener{
          public void actionPerformed(ActionEvent e){
             Object select = e.getSource();
             if (select.equals(left)){
                 point.x = point.x - 5;
                 repaint();
             }
             if (select.equals(right)){
                 point.x = point.x + 5;
                 repaint();
             }
             if (select.equals(reset)){
                 point.reset();
                 repaint();
             }
             if (select.equals(save)){
                 point.savePos("D:/coordinates.txt");
                 repaint();
             }
             if (select.equals(load)){
                 point.loadPos("D:/coordinates.txt");
                 repaint();
             }
          }
        }
       public static void main(String[] args){
          MyFrame f1 = new MyFrame();
          f1.addpanel1();
          f1.addpanel2();
       }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Please anyone can you fix my Code??

    This looks like the same problem as this:

    http://www.javaprogrammingforums.com...html#post65560


    Why start a new thread for the same problem?

    Why didn't you reply to my last post?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Mar 2012
    Location
    United States
    Posts
    118
    My Mood
    Inspired
    Thanks
    1
    Thanked 33 Times in 31 Posts

    Default Re: Please anyone can you fix my Code??

    What issue(s) are you having specifically? Does the code compile? Are you getting any error message(s)? If so please post the full error message text. This forum does not act as a code service, but I'm sure you can find help here if you answer the questions I suggested.


    EDIT: Didn't realize this was, basically, a duplicate post and it would seem the original is more concise.

Similar Threads

  1. How to Translate working code into code with a Tester Class
    By bankoscarpa in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 15th, 2012, 02:13 PM
  2. code to refresh and check the code of a webpage..
    By vaggelis in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 7th, 2012, 07:43 AM
  3. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 08:36 AM
  4. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM
  5. describe this program code by code ....
    By izzahmed in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 29th, 2011, 11:03 PM

Tags for this Thread