Results 1 to 2 of 2
  1. #1
    fernando is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default I am trying to create a wheel that has 5 spokes...

    Hi, I am trying to create a wheel that has 5 spokes. I am kind of new at Java and need some help completing this. So far I have:

    Java Code:
    import java.applet.Applet;
    import java.awt.Graphics;
    
    import javax.swing.JFrame;
    
    public class DrawOval extends Applet
    {
    public void paint(Graphics g)
    {
    g.drawOval(10, 50, 200,
    getSize() .height - 384);
    getSize() .getWidth();
    Thanks.

  2. #2
    baltimore is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default

    Please check this:

    Java Code:
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.geom.Ellipse2D;
    import java.awt.geom.Line2D;
    import java.awt.geom.Rectangle2D;
    import java.awt.Stroke;
    import java.awt.BasicStroke;
    
    class Wheel extends JFrame {
    private MyPanel panel=null;
    public static void main(String[] args) {
    new Wheel();
    }
    public Wheel() {
    setTitle("Wheel");
    panel = new MyPanel();
    panel.setPreferredSize(new Dimension(210,210));
    getContentPane().add(panel);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setLocationRelativeTo(null);
    setVisible(true);
    }
    
    class MyPanel extends JPanel {
    MyPanel() {
    super();
    }
    
    public void paintComponent(Graphics g) {
    g.clearRect(0,0,(int) getPreferredSize().getWidth(),(int) getPreferredSize().getHeight());
    g.setColor(Color.BLACK);
    Ellipse2D.Double circle = new Ellipse2D.Double(0, 0, 200, 200);
    
    Graphics2D g2d = (Graphics2D)g;
    
    BasicStroke stroke = new BasicStroke(10.0f);
    
    g2d.setStroke(stroke);
    g2d.draw(new Line2D.Double(0, 100, 100, 100));
    g2d.draw(new Line2D.Double(100, 100, 200, 100));
    
    g2d.draw(new Line2D.Double(100, 0, 100, 100));
    g2d.draw(new Line2D.Double(100, 100, 100, 200));
    
    g2d.draw(new Line2D.Double(25, 25, 100, 100));
    g2d.draw(new Line2D.Double(100, 100, 175, 175));
    
    g2d.draw(new Line2D.Double(175, 25, 100, 100));
    g2d.draw(new Line2D.Double(100, 100, 25, 175));
    
    g2d.draw(circle);
    
    }
    
    
    }
    
    }

Similar Threads

  1. Vector create
    By Warren in forum New To Java
    Replies: 4
    Last Post: 03-02-2010, 02:42 AM
  2. Create a new variable
    By mathias in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:48 AM
  3. how to create different arrays
    By osval in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 11:07 PM
  4. Create XML From XSD
    By Jack in forum XML
    Replies: 1
    Last Post: 07-09-2007, 12:56 AM
  5. I need create a JSplitPane
    By Daniel in forum AWT / Swing
    Replies: 1
    Last Post: 07-05-2007, 06:12 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
  •