Results 1 to 3 of 3
  1. #1
    ren66a66 is offline Member
    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Default Help T T i'm so frustrating now

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;

    public class Battleship extends JFrame{

    public static void main( String args[] ) {
    new Battleship();

    }

    Canvas canvas=new Canvas() {
    public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d=(Graphics2D) g;
    int x1Ver=150,y1Ver=200,y2Ver=500;
    int x1Hor=150,y1Hor=200,x2Hor=450;
    for(int draw=0;draw<11;draw++){
    g.drawLine(x1Ver, y1Ver, x1Ver, y2Ver);
    g.drawLine(x1Hor, y1Hor, x2Hor, y1Hor);
    x1Ver+=30;
    y1Hor+=30;
    }

    }
    };

    public Battleship(){
    JFrame f=new JFrame("Battleship");
    f.setTitle("Battleship");
    f.setSize(1000, 900);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
    f.setResizable(false);
    f.setLocationRelativeTo(null);
    f.add(new GraphicsSurface());

    JButton close=new JButton("Close");
    close.setBounds(500, 500, 100, 100);

    JPanel panel=new JPanel();
    panel.setLayout(null);
    panel.setVisible(true);
    panel.add(close);
    f.getContentPane().add(panel);

    panel.add(close);


    }



    }




    i wrote this, but i don't understand why java won't draw the shape for me. Please enlighten me! Thanks!!

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,879
    Rep Power
    8

    Default Re: Help T T i'm so frustrating now

    When posting code, please use the code tags to preserve formatting.

    Don't add components to a container that's already visible. If you absolutely have to, then revalidate the component afterwards.

    Why are you extending JFrame?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Help T T i'm so frustrating now

    Additionally, avoid mixing Swing and AWT components. Use JPanel or JComponent, not Canvas.

    Guide For New Members
    BB Code List - Java Programming Forum - Learn Java Programming

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

Similar Threads

  1. Frustrating simple problem.
    By Addez in forum New To Java
    Replies: 2
    Last Post: 09-15-2011, 08:23 PM
  2. What's the most frustrating thing about JAVA?
    By conopoly in forum New To Java
    Replies: 17
    Last Post: 06-30-2011, 06:37 PM
  3. Simple but frustrating error
    By JoeHill in forum New To Java
    Replies: 10
    Last Post: 06-02-2011, 09:28 AM
  4. very frustrating.. recursive
    By Yakg in forum New To Java
    Replies: 5
    Last Post: 01-06-2011, 10:25 PM
  5. Please help setting up Tomcat. Very frustrating.
    By wombatvvv in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 09-12-2010, 05:56 AM

Posting Permissions

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