Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
knarate
knarate's Profile
1
Posts
0
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
How to add image to JFrame
[1 Reply]
15-Nov-2010 10:41 PM
Forum:
Programming Questions
I'm new in Processing I try to add image to JFrame but it can't display an image, Help me please.
########### MyFrame.pde ############
import javax.swing.*;
import java.awt.*;
class MyFrame extends JFrame {
MyFrame() {
JFrame f = new JFrame("My Frame");
f.setSize(400, 600);
f.setLocationRelativeTo(null);
f.setResizable(false);
f.setVisible(true);
f.add(new ImagePanel());
}
}
class ImagePanel extends JPanel {
ImagePanel(){}
Image img = Toolkit.getDefaultToolkit().getImage("image_name.png");
void paint(Graphics g) {
g.drawImage(img, 0, 0, this);
super.paint(g);
}
}
############ Test.pde ##############
void setup(){
size(400,600);
}
void draw(){
//...
}
void mousePressed(){
MyFrame frame = new MyFrame();
}
«Prev
Next »
Moderate user : knarate
Forum