Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 1 decade ago

graphics in java using bluej?

what do i need to do to insert graphics in a program written in java using bluej?

and is it possible to insert a clipart in the program?

thanks

4 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    try this

    import javax.swing.*;

    import java.awt.*;

    public class Frame extends JPanel

    {

    public Frame()

    {

    JFrame frame=new JFrame();

    frame.add(this);

    frame.setSize(640, 480);

    frame.setDefaultCloseOperation(

    JFrame.EXIT_ON_CLOSE);

    frame.setVisible(true);

    }

    public void paint(Graphics g) {

    Graphics2D g2=(Graphics2D)g;

    g2.setColor(Color.WHITE);

    g2.fillRect(0,0,getWidth(),getHeight());

    g2.setColor(Color.BLACK);

    g2.drawRect(100,100,200,200);

    }

    }

    Look at

    http://java.sun.com/javase/6/docs/api/

    You can use all the methods from the Graphics and Graphics2D classes on g2.

    To insert a clipart you can either do this

    import java.io.*;

    import javax.imageio.*;

    and then

    try {

    image=ImageIO.read(new File("c:/image.jpg"));

    } catch(Exception e) {

    }

    and

    public void paint(Graphics g) {

    g.drawImage(image,0,0,null);

    }

    or you do this

    public Frame()

    {

    JFrame frame=new JFrame();

    frame.add(new JLabel(new ImageIcon("c:/image.jpg")));

    frame.pack();

    frame.setDefaultCloseOperation(

    JFrame.EXIT_ON_CLOSE);

    frame.setVisible(true);

    }

  • Anonymous
    4 years ago

    Using Bluej

  • 6 years ago

    Click on the options

    Yes it is possible

  • 1 decade ago

    rrrrrr

Still have questions? Get your answers by asking now.