Results 1 to 5 of 5

Thread: NEW Assignment CSC105

  1. #1
    Junior Member
    Join Date
    Jun 2004
    Location
    Thailand
    Posts
    26


    NEW Assignment CSC105

    Hello my friends. I've finish java assignment on last tuesday.
    You can look at my applet from link below.
    Here
    Certainly, I've post the java code below.
    This code is simple shape. You can write another method to draw other shape.
    If you have a question you can ask me by post message in this webboard or ask me during daytime.
    Good luck to U.

  2. #2
    Junior Member
    Join Date
    Jun 2004
    Location
    Thailand
    Posts
    26


    Pict.class

    [src]import java.awt.*;
    public class Pict extends Canvas
    {
    private Color col = new Color(5);
    private int pic = 0;
    public void setColor(Color c)
    {
    col = c;
    }
    public void setPict(String p)
    {
    if (p=="Square")
    pic = 1;
    else if (p=="Circle")
    pic = 2;

    }
    public void paint(Graphics g)
    {
    g.setColor(col);
    switch (pic)
    {
    case 1 : drawRect(g);break;
    case 2 : drawOval(g);break;
    }
    }
    public void drawRect(Graphics g)
    {
    g.drawRect(100,25,100,100);
    g.fillRect(100,150,100,100);
    }
    public void drawOval(Graphics g)
    {
    g.drawOval(100,25,100,100);
    g.fillOval(100,150,100,100);
    }
    }[/src]

  3. #3
    Junior Member
    Join Date
    Jun 2004
    Location
    Thailand
    Posts
    26


    DrawGUI.class

    [src]import CSLib.*;
    import java.awt.*;
    import java.awt.event.*;

    public class DrawGUI extends ClosableFrame
    implements ActionListener,ItemListener
    {
    Pict c = new Pict();
    Choice choice1 = new Choice();
    Button
    bRed = new Button("Red"),
    bGreen = new Button("Green"),
    bBlue = new Button("Blue"),
    bBlack = new Button("Black"),
    bQuit = new Button("Quit");
    Panel butts = new Panel();

    public DrawGUI()
    {
    choice1.addItem("");
    choice1.addItem("Square");
    choice1.addItem("Circle");
    butts.setLayout(new GridLayout(1,5));
    butts.add(bRed);
    butts.add(bGreen);
    butts.add(bBlue);
    butts.add(bBlack);
    butts.add(bQuit);
    setLayout(new BorderLayout());
    add("North",choice1);
    add("Center",c);
    add("South",butts);
    bRed.addActionListener(this);
    bGreen.addActionListener(this);
    bBlue.addActionListener(this);
    bBlack.addActionListener(this);
    bQuit.addActionListener(this);
    choice1.addItemListener(this);
    c.setSize(300,300);
    c.setBackground(Color.lightGray);
    pack();
    setVisible(true);
    }
    public void actionPerformed(ActionEvent e)
    {
    if (e.getSource()==bRed)
    c.setColor(Color.red);
    else if (e.getSource()==bGreen)
    c.setColor(Color.green);
    else if (e.getSource()==bBlue)
    c.setColor(Color.blue);
    else if (e.getSource()==bBlack)
    c.setColor(Color.black);
    else if (e.getSource()==bQuit)
    {
    getGraphics().dispose();
    System.exit(1);
    }
    c.repaint();

    }
    public void itemStateChanged(ItemEvent e)
    {
    if (e.getSource()==choice1)
    {
    if (choice1.getSelectedItem()=="Square")
    c.setPict("Square");
    else if (choice1.getSelectedItem()=="Circle")
    c.setPict("Circle");
    }
    c.repaint();
    }
    }
    [/src]

  4. #4
    Junior Member
    Join Date
    Jun 2004
    Location
    Thailand
    Posts
    26


    DrawClient.class

    [src]public class DrawClient
    {
    public static void main(String args[])
    {
    new DrawGUI();
    }
    }
    [/src]

  5. #5
    Junior Member
    Join Date
    Jun 2004
    Location
    Thailand
    Posts
    26


    Conclusion

    The given code has 3 class.
    You don't forget to copy package CSLib to folder because CSLib contains class name ClosableFrame.
    I hope that code that I've posted can help you to understand the assignment very well.
    You shouldn't copy all of my code.
    The best way is you should implement this code and understand it.

Similar Threads

  1. Replies: 0
    Last Post: 08-12-2008, 11:27 PM
  2. Replies: 0
    Last Post: 22-11-2008, 05:04 PM
  3. Replies: 16
    Last Post: 30-08-2008, 01:00 AM
  4. CSC105 Assignment
    By massiah in forum Java
    Replies: 12
    Last Post: 03-11-2004, 09:54 AM
  5. assignment aj udom
    By armano in forum Announcement
    Replies: 4
    Last Post: 02-03-2003, 06:03 PM

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Tags for this Thread

Posting Permissions

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