Results 1 to 2 of 2
- 03-02-2011, 08:01 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 47
- Rep Power
- 0
Graphics issue, pic won't show up.
Hi.
Making a menu for my game, and then i've made a picture with instructions to be shown in a new JFrame, next to the menus JFrame. But the image won't show up in my new JFrame. All the code:
PHP Code:import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Menu extends JFrame implements ActionListener{ private ImageIcon image; private JButton start; public Menu(){ super("Main Menu"); setLayout(null); start = new JButton("Start"); start.setBounds(0, 60, 195, 30); setVisible(true); setResizable(false); setSize(200, 250); setLocation(650, 250); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); start.addActionListener(this); add(start); } public void actionPerformed(ActionEvent e) { if(e.getSource() == start){ new Rules(); } } public class Rules extends JPanel implements ActionListener{ public Rules(){ JFrame rules = new JFrame("How to"); rules.setLayout(null); rules.setVisible(true); rules.setResizable(false); rules.setSize(400, 250); rules.setLocation(850, 250); rules.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void paintComponent(Graphics g){ super.paintComponent(g); image = new ImageIcon("imgs/Ibz.png"); image.paintIcon(this, g, 0, 0); Graphics2D g2 = (Graphics2D) g; } @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub } } }
- 03-02-2011, 08:44 PM #2
Don't perform file I/O or business logic in a painting method override. Painting methods are strictly for painting.
Load the image to an instance field in the constructor, and paint it in the paintComponent override. Also, don't needlessly construct an ImageIcon -- you can load an Image using ImageIO#read(...)
db
Similar Threads
-
Cross-Browser Issue with show/hide divs
By jmchaffie in forum New To JavaReplies: 3Last Post: 03-10-2011, 09:41 AM -
Graphics wont show up(paintComponent)
By TheBreadCat in forum New To JavaReplies: 3Last Post: 02-13-2011, 06:00 PM -
Drawing a graphics onto another Graphics ?
By Ziden in forum Java AppletsReplies: 0Last Post: 01-08-2011, 07:30 PM -
how to show web browser in mobile app or is it possible to show it in textArea
By Basit781 in forum CLDC and MIDPReplies: 3Last Post: 05-27-2010, 10:54 AM -
netbeans 6.0 not show commpunent or show blank page
By fahimaamir in forum NetBeansReplies: 1Last Post: 01-26-2008, 06:20 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks