Results 1 to 3 of 3
Thread: challenge for swing programmers
- 12-24-2008, 07:04 PM #1
-
Let's see your attempt. What you should do is to write a very small compilable app that does nothing at all except try to show a BMP picture in the JFrame. Post it here with code tags and let's see what we can do to help you along. Oh, also are you using ImageIO to read in the BMP?
-
Here's my attempt:
Java Code:import java.awt.Dimension; import java.awt.Graphics; import java.awt.Image; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import javax.imageio.ImageIO; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; public class ShowBMP { private static final String IMAGE_PATH = "http://wvnvaxa.wvnet.edu/vmswww/images/test32v5.bmp"; private JPanel mainPanel = new JPanel() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (image != null) { g.drawImage(image, 0, 0, this); } } }; Image image; public ShowBMP() { try { image = ImageIO.read(new URL(IMAGE_PATH)); int width = image.getWidth(mainPanel); int height = image.getHeight(mainPanel); mainPanel.setPreferredSize(new Dimension(width, height)); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public JComponent getPanel() { return mainPanel; } private static void createAndShowGUI() { JFrame frame = new JFrame("ShowBMP Application"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new ShowBMP().getPanel()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }
Similar Threads
-
Ultimate challenge in JComboBox
By vaidhu in forum AWT / SwingReplies: 3Last Post: 08-21-2008, 06:56 PM -
Looking for JAVA Programmers!
By offshoring in forum Jobs OfferedReplies: 0Last Post: 02-05-2008, 06:52 AM -
Hello java programmers...
By coder_ in forum IntroductionsReplies: 2Last Post: 01-23-2008, 05:23 AM -
java programming challenge Number 1
By tacosalad in forum New To JavaReplies: 5Last Post: 01-16-2008, 10:25 PM -
The Million Musician Challenge 0.821
By levent in forum Java SoftwareReplies: 0Last Post: 05-25-2007, 07:39 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks