Image in PersonalJava
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Christer_Nordvik
Posted On:   Friday, October 12, 2001 03:51 AM

How do you draw images on panels using ONLY awt(PersonalJava)?


I want to draw 5 jpgs in my GUI, but haven't figured out how to do it. I guess I must subclass the paintComponent method but I didn't get it to work. I used the ImageControl(Borland specific control) but that control depended on JComponent which is Swing. Any help would be greatly appreciated.




-Christer

Re: Image in PersonalJava

Posted By:   anu_rag  
Posted On:   Monday, October 15, 2001 06:36 AM


import java.awt.*;
import java.awt.event.*;
import java.awt.*;
import java.applet.Applet;
//

public class Lesson3a extends Applet implements ActionListener{
Image walsh[];
Button front, top, left, right;
WalshView view; // WalshView is an inner class
Font f1;

public void init () {
walsh = new Image[4];
// First load up the images
for(int i = 0; i < 4; i++)
walsh[i] = getImage(getDocumentBase(),"pic"+i+".jpg");
// First generate the GUI objects with initial states
front = new Button( "+");
top = new Button("Mug Shot Project");
left = new Button("<");
right = new Button(">");
view = new WalshView(0);
// Set the font on the GUI
f1 = new Font("TimesRoman",Font.PLAIN,16);
front.setFont(f1);
top.setFont(f1);
left.setFont(f1);
right.setFont(f1);
// Configure the appearance of the GUI
setLayout(new BorderLayout() );
add("North",top);
add("Center",view);
add("West",left);
add("East",right);
add("South",front);
// Connect up the event handling
front.addActionListener(this);
top.addActionListener(this);
right.addActionListener(this);
left.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String command = e.getActionCommand();
if(command == "+") {
view.image = 0;
view.repaint();
}
if(command == "<") {
view.image = 1;
view.repaint();
}
if(command == ">") {
view.image = 2;
view.repaint();
}
if(command == "Mug Shot Project") {
view.image = 3;
view.repaint();
}
}
public class WalshView extends Canvas {
int image;
public WalshView(int i) {
image = i;

}
public void paint(Graphics g) {

g.drawImage(walsh[image],0,0,this);
}
}
}
About | Sitemap | Contact