|
|
#1 (permalink) | ||
|
Deal Addict
![]() ![]() ![]() ![]() ![]() Join Date: May 24th, 2004
Location: Victoria
Posts: 1,181
|
Hi, for the programming course at school I need to figure out how to display a jpg image in java in an application, not applet, at the end of a game that I wrote. Can anyone help me out? thanks!
__________________
I hope Life isn't one big joke because I don't get it. |
||
|
|
|
| Sponsored Links - Join the RedFlagDeals.com community and remove this ad. |
|
|
#3 (permalink) | ||
|
Deal Addict
![]() ![]() ![]() ![]() ![]() Join Date: May 24th, 2004
Location: Victoria
Posts: 1,181
|
i'm ******** at swing....(I can only do really basic level programming) but can you post some demo code? the stuff i find on google won't compile..maybe i'm doing something wrong. I'm using ConTEXT and compiling stuff through there.
__________________
I hope Life isn't one big joke because I don't get it. |
||
|
|
|
|
|
#4 (permalink) | ||
|
Member
Join Date: Apr 12th, 2004
Location: Victoria BC
Posts: 248
|
import java.awt.*;
import java.awt.event.*; import java.io.*; import java.util.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import javax.swing.border.*; /** * Creates a new Display GUI. */ public class DisplayGUI extends JFrame { JLabel arrayStatus; JLabel clustersStatus; JLabel sensorsStatus; JLabel averageStatus; JCheckBox showClusters; JRadioButton Topology; JRadioButton Temperature; JRadioButton Moisture; JRadioButton Sunlight; JMenuItem[] TTMSMenuItem; JScrollPane scrollPane; Grapher graph; JPanel graphPanel; topologyPane topoPane; ButtonGroup selectionGroup = new ButtonGroup(); Controller parent; /** * Creates a Display GUI with the given controller * @param parent the controller */ public DisplayGUI(Controller parent) { this.parent = parent; enableEvents(AWTEvent.WINDOW_EVENT_MASK); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } show(); } /* init the GUI */ private void jbInit() throws Exception { this.getContentPane().setLayout(null); this.setResizable(false); this.setTitle("Seng 330 - PROJECT"); this.setBounds(new java.awt.Rectangle(22, 22, 577,415));//);577, 407)); this.setIconImage(new ImageIcon("resources/icon_thing.gif").getImage()); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); setLocation((d.width-getWidth())/2, (d.height-getHeight())/2); JMenu menu = new JMenu("File"); menu.setMnemonic(KeyEvent.VK_F); //================================================= JMenuItem item = new JMenuItem("New Deployment"); item.setMnemonic(KeyEvent.VK_N); item.addActionListener(parent.getListener()); menu.add(item); //================================================= item = new JMenuItem("Exit"); item.setMnemonic(KeyEvent.VK_E); item.addActionListener(new ExitListener()); menu.add(item); // --------------------------------------------- JMenu menu2 = new JMenu("Settings"); menu.setMnemonic(KeyEvent.VK_S); //================================================= TTMSMenuItem = new JMenuItem[4]; TTMSMenuItem[0] = new JMenuItem("Topology"); TTMSMenuItem[0].setMnemonic(KeyEvent.VK_T); TTMSMenuItem[0].addActionListener(parent.getListener()); menu2.add(TTMSMenuItem[0]); //================================================= TTMSMenuItem[1] = new JMenuItem("Temperature"); TTMSMenuItem[1].setMnemonic(KeyEvent.VK_P); TTMSMenuItem[1].addActionListener(parent.getListener()); menu2.add(TTMSMenuItem[1]); //================================================= TTMSMenuItem[2] = new JMenuItem("Moisture"); TTMSMenuItem[2].setMnemonic(KeyEvent.VK_M); TTMSMenuItem[2].addActionListener(parent.getListener()); menu2.add(TTMSMenuItem[2]); //================================================= TTMSMenuItem[3] = new JMenuItem("Sunlight"); TTMSMenuItem[3].setMnemonic(KeyEvent.VK_S); TTMSMenuItem[3].addActionListener(parent.getListener()); menu2.add(TTMSMenuItem[3]); // --------------------------------------------- JMenu menu3 = new JMenu("Help"); menu.setMnemonic(KeyEvent.VK_H); //================================================= item = new JMenuItem("About"); item.setMnemonic(KeyEvent.VK_A); item.addActionListener(new AboutListener()); menu3.add(item); // --------------------------------------------- //================================================= JMenuBar menuBar = new JMenuBar(); menuBar.setMargin(new Insets(5,5,5,5)); menuBar.add(menu); menuBar.add(menu2); menuBar.add(menu3); this.setJMenuBar(menuBar); // --------------------------------------------- //================================================= JLabel jLabel1 = new JLabel(); jLabel1.setText(" Current Graph System "); jLabel1.setOpaque(true); getContentPane().add(jLabel1); jLabel1.setBounds(24, -3, 125, 16); JPanel jPanel1 = new JPanel(); jPanel1.setBorder(new javax.swing.border.EtchedBorder()); jPanel1.setBounds(4, 4, 400, 330); getContentPane().add(jPanel1); graphPanel = new JPanel(); graphPanel.setLayout(null); graphPanel.setVisible(false); graphPanel.setBounds(new java.awt.Rectangle(5, 100, 350 , 200)); graph = new Grapher(); graph.setVisible(false); graph.setXtag("-- Time --"); graph.setBounds(new java.awt.Rectangle(0, 0, 350 , 200)); graphPanel.add(graph); topoPane = new topologyPane(null); topoPane.setVisible(true); scrollPane = new JScrollPane(scrollPane.VERTICAL_SCROLLBAR_AS_NEEDE D,scrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setPreferredSize(new Dimension(395,320)); scrollPane.setViewportView(graphPanel); scrollPane.setViewportView(topoPane); scrollPane.add(graphPanel); jPanel1.add(scrollPane); // --------------------------------------------- //================================================= jLabel1 = new JLabel(); jLabel1.setText(" Display Options "); jLabel1.setOpaque(true); jLabel1.setBounds(424,-3, 95, 16); getContentPane().add(jLabel1); showClusters = new JCheckBox(); showClusters.setText("Show Cluster Header"); showClusters.setFocusPainted(false); showClusters.setSelected(true); showClusters.addActionListener(parent.getListener( )); getContentPane().add(showClusters,0); showClusters.setBounds(416, 15, 150, 24); Topology= new JRadioButton("Topology"); Topology.setBounds(416, 42, 150, 24); selectionGroup.add(Topology); Topology.setFocusPainted(false); Topology.setSelected(true); Topology.addActionListener(parent.getListener()); getContentPane().add(Topology,0); Temperature= new JRadioButton("Temperature"); Temperature.setBounds(416, 62, 150, 24); selectionGroup.add(Temperature); Temperature.setFocusPainted(false); Temperature.addActionListener(parent.getListener() ); getContentPane().add(Temperature,0); Moisture= new JRadioButton("Moisture"); Moisture.setBounds(416, 82, 150, 24); selectionGroup.add(Moisture); Moisture.setFocusPainted(false); Moisture.addActionListener(parent.getListener()); getContentPane().add(Moisture,0); Sunlight= new JRadioButton("Sunlight"); Sunlight.setBounds(416, 102, 150, 24); selectionGroup.add(Sunlight); Sunlight.setFocusPainted(false); Sunlight.addActionListener(parent.getListener()); getContentPane().add(Sunlight,0); JPanel jPanel2 = new JPanel(); jPanel2 = new JPanel(); jPanel2.setBorder(new javax.swing.border.EtchedBorder()); jPanel2.setBounds(408, 4, 160, 155); getContentPane().add(jPanel2); // --------------------------------------------- jLabel1 = new JLabel(); jLabel1.setText(" Legends "); jLabel1.setOpaque(true); getContentPane().add(jLabel1); jLabel1.setBounds(424, 155, 60, 16); jPanel1 = new JPanel(); jPanel1.setBorder(new javax.swing.border.EtchedBorder()); jPanel1.setBounds(408, 164, 160, 170); getContentPane().add(jPanel1); jLabel1 = new JLabel(new ImageIcon("resources/legend.png"));//new ImageIcon("resources/icon_thing.gif").getImage()); jLabel1.setBounds(0, 0, 200, 200); jLabel1.setVisible(true); jPanel1.add(jLabel1); arrayStatus = new JLabel(); arrayStatus.setText("80x80"); arrayStatus.setBorder(new javax.swing.border.EtchedBorder()); arrayStatus.setBounds(4, 336, 60, 22); arrayStatus.setHorizontalAlignment(javax.swing.Swi ngConstants.CENTER); getContentPane().add(arrayStatus); clustersStatus = new JLabel(); clustersStatus.setText("#Clusters = 415"); clustersStatus.setBorder(new javax.swing.border.EtchedBorder()); clustersStatus.setBounds(68, 336, 110, 22); clustersStatus.setHorizontalAlignment(javax.swing. SwingConstants.CENTER); getContentPane().add(clustersStatus); sensorsStatus = new JLabel(); sensorsStatus.setText("#Sensors = 2415"); sensorsStatus.setBorder(new javax.swing.border.EtchedBorder()); sensorsStatus.setBounds(182, 336, 150, 22); sensorsStatus.setHorizontalAlignment(javax.swing.S wingConstants.CENTER); getContentPane().add(sensorsStatus); averageStatus = new JLabel(); averageStatus.setText("Average = 15 | Max = 25 | Min = 10"); averageStatus.setBorder(new javax.swing.border.EtchedBorder()); averageStatus.setBounds(336, 336, 232, 22); averageStatus.setHorizontalAlignment(javax.swing.S wingConstants.CENTER); getContentPane().add(averageStatus); this.setVisible(true); this.repaint(); } |
||
|
|
|
|
|
#5 (permalink) | ||
|
Member
Join Date: Apr 12th, 2004
Location: Victoria BC
Posts: 248
|
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) { cancel(); System.exit(0); } super.processWindowEvent(e); } /** * Used to dipose of GUI */ void cancel() { dispose(); } /** * Set the status bar with the default values. */ public void setBottomInfo(){ averageStatus.setText("Average = n/a | Max = n/a | Min = n/a"); Preferences p = Preferences.getInstance(); sensorsStatus.setText("#Sensors = "+p.getClusterCount()*p.getSensorsPerHead()); clustersStatus.setText("#Clusters = "+p.getClusterCount()); int cols=p.getPhysicalWidth()/ p.getClusterCoverageLength(); int rows=p.getClusterCount()/ cols; if (p.getClusterCount()% cols!=0)rows++; arrayStatus.setText(cols+"x"+rows); } public void setAverageStatus(int avg,int max,int min){ averageStatus.setText("Average = "+avg+" | Max = "+max+" | Min = "+min); } /** * Set the view to the topologyPane or grapher depending on topoPaneOn value * @param topoPaneOn set topologyPane visible is true else false */ public void setTopology(boolean topoPaneOn){ graphPanel.setVisible(!topoPaneOn); graph.setVisible(!topoPaneOn); parent.redraw_topology(); topoPane.setVisible(topoPaneOn); scrollPane.getHorizontalScrollBar().setEnabled(top oPaneOn); scrollPane.getHorizontalScrollBar().setVisible(top oPaneOn); scrollPane.getVerticalScrollBar().setEnabled(topoP aneOn); scrollPane.getVerticalScrollBar().setVisible(topoP aneOn); } class ExitListener implements ActionListener{ public void actionPerformed(ActionEvent ae){System.exit(0);} } class AboutListener implements ActionListener{ public void actionPerformed(ActionEvent ae){ JOptionPane.showMessageDialog( null, "Date:March 28,2004\n"+ "Thank you\n\n" , "About", JOptionPane.INFORMATION_MESSAGE ); } } } |
||
|
|
|
|
|
#6 (permalink) | ||
|
Member
Join Date: Apr 12th, 2004
Location: Victoria BC
Posts: 248
|
especially look for something like
jPanel1 = new JPanel(); jPanel1.setBorder(new javax.swing.border.EtchedBorder()); jPanel1.setBounds(408, 164, 160, 170); getContentPane().add(jPanel1); jLabel1 = new JLabel(new ImageIcon("resources/legend.png"));//new ImageIcon("resources/icon_thing.gif").getImage()); jLabel1.setBounds(0, 0, 200, 200); jLabel1.setVisible(true); jPanel1.add(jLabel1); |
||
|
|
|
|
|
#8 (permalink) | ||
|
Member
Join Date: Apr 12th, 2004
Location: Victoria BC
Posts: 248
|
definately not
![]() tihs is enough jPanel1 = new JPanel(); jPanel1.setBorder(new javax.swing.border.EtchedBorder()); jPanel1.setBounds(408, 164, 160, 170); getContentPane().add(jPanel1); jLabel1 = new JLabel(new ImageIcon("resources/legend.png"));//new ImageIcon("resources/icon_thing.gif").getImage()); jLabel1.setBounds(0, 0, 200, 200); jLabel1.setVisible(true); jPanel1.add(jLabel1); |
||
|
|
|
|
|
#10 (permalink) | ||
|
Sr. Member
![]() ![]() ![]() ![]() Join Date: Nov 21st, 2002
Location: Hong Kong
Posts: 655
|
Quote:
|
||
|
|
|
|
|
#12 (permalink) | ||
|
Deal Guru
![]() ![]() ![]() ![]() ![]() Join Date: Nov 20th, 2002
Location: Mississauga
Posts: 12,453
|
Quote:
__________________
Heatware 50 Positive, 0 Negative |
||
|
|
|
|
|
#13 (permalink) | ||
|
Member
Join Date: Apr 12th, 2004
Location: Victoria BC
Posts: 248
|
Quote:
well you can go this getContentPane().add(new JLabel(new ImageIcon("resources/legend.png"))); and i guess you never used any of the real programming languages like 10-15 years ago when displaying JPG took close to 2000 lines. now they make it too easy for newbies they dont appriciate how easy they have it. |
||
|
|
|
|
|
#15 (permalink) | ||
|
Deal Addict
![]() ![]() ![]() ![]() ![]() Join Date: Aug 14th, 2002
Posts: 3,880
|
Quote:
|
||
|
|
|
![]() |
| Thread Tools | |
|
|
| Canadian Coupons Deals Features Freebies Forums Retailer Ratings Marketplace Credit Card Comparison Computer Price Comparison |

Join a community of over 200,000 bargain hunters from all across Canada. As a member you can post comments, ask questions, and share deals, coupons, and freebies! Best of all, signing up is free!