Results 1 to 4 of 4
  1. #1
    Godzilla is offline Member
    Join Date
    Jul 2007
    Posts
    3
    Rep Power
    0

    Default Basic graphics applet

    Hi I have written this code:

    Java Code:
     g.setColor(Color.white);
      g.fillRect(0,0,500,300);
    
    g.setStroke(new BasicStroke(60));
      g.setColor(Color.green);
      g.drawLine(0,0,500,300);
    
    g.setStroke(new BasicStroke(60));
      g.setColor(Color.green);
      g.drawLine(500,0,0,300);
    
    g.setStroke(new BasicStroke(60));
      g.setColor(Color.red);
      g.drawLine(250,0,250,300);
    
    g.setStroke(new BasicStroke(60));
      g.setColor(Color.red);
      g.drawLine(0,150,500,150);
    Can anyone help me make an applet from this code that draws a flag and keeps its aspect ratio 2:1. Thanks for any help :D

  2. #2
    goldhouse is offline Senior Member
    Join Date
    Mar 2007
    Posts
    134
    Rep Power
    0

    Default

    Ok I will help you to make it in an easy download netbeans , and drag and drop whatever you want , just click on the Play '>' button you will have what you want. Just play around with the colors as you please you will have no trouble if you are sure you dont want to add any functionalities

  3. #3
    Godzilla is offline Member
    Join Date
    Jul 2007
    Posts
    3
    Rep Power
    0

    Default

    Hey goldhouse, thanks for the reply but I don't understand what you want me to do. I have Netbeans IDE 5.0.

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Here's something to get you started. Your code has an aspect ratio of 5:3.
    Java Code:
    //  <applet code="FlagApplet" width="500" height="300"></applet>
    import java.awt.*;
    import javax.swing.*;
    
    public class FlagApplet extends JApplet {
        public void init() {
            getContentPane().add(new FlagPanel());
        }
    
        private class FlagPanel extends JPanel {
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2 = (Graphics2D)g;
                g.setColor(Color.white);
                g.fillRect(0,0,500,300);
    
                g2.setStroke(new BasicStroke(60));
                g.setColor(Color.green);
                g.drawLine(0,0,500,300);
    
    //            g.setStroke(new BasicStroke(60));
                g.setColor(Color.green);
                g.drawLine(500,0,0,300);
    
    //            g.setStroke(new BasicStroke(60));
                g.setColor(Color.red);
                g.drawLine(250,0,250,300);
    
    //            g.setStroke(new BasicStroke(60));
                g.setColor(Color.red);
                g.drawLine(0,150,500,150);
            }
        }
    }

Similar Threads

  1. Eclipse Applet Viewer not showing graphics?
    By sjchase in forum Java Applets
    Replies: 1
    Last Post: 04-17-2008, 04:16 PM
  2. Graphics
    By Joe2003 in forum Advanced Java
    Replies: 1
    Last Post: 01-25-2008, 06:24 PM
  3. graphics
    By Joe2003 in forum Advanced Java
    Replies: 4
    Last Post: 01-18-2008, 07:44 PM
  4. Basic Applet
    By jkswebsite in forum Java Applets
    Replies: 4
    Last Post: 01-13-2008, 09:14 PM
  5. Graphics
    By feniger in forum New To Java
    Replies: 1
    Last Post: 12-29-2007, 04:22 PM

Posting Permissions

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