hide   Never miss a deal of the day with our Daily Deals Section!
Stretch interface sizeReset interface & text size
Go Back   RedFlagDeals.com Forums > Computers & Electronics
Sponsored by:

Reply  
 
Thread Tools
Old May 23rd, 2005, 06:26 PM   #1 (permalink)
Deal Addict
 
Join Date: May 24th, 2004
Location: Victoria
Posts: 1,181
Default Java programmers look inside!

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.
Slimfast is offline  
Send a private message to Slimfast Reply With Quote
Sponsored Links - Join the RedFlagDeals.com community and remove this ad.
Old May 23rd, 2005, 06:32 PM   #2 (permalink)
Member
 
Join Date: Apr 12th, 2004
Location: Victoria BC
Posts: 248
Default

not applet,

can you at least use swing?
mprielozny is offline  
Send a private message to mprielozny Reply With Quote
Old May 23rd, 2005, 06:35 PM   #3 (permalink)
Deal Addict
 
Join Date: May 24th, 2004
Location: Victoria
Posts: 1,181
Default

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.
Slimfast is offline  
Send a private message to Slimfast Reply With Quote
Old May 23rd, 2005, 06:58 PM   #4 (permalink)
Member
 
Join Date: Apr 12th, 2004
Location: Victoria BC
Posts: 248
Default

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();
}
mprielozny is offline  
Send a private message to mprielozny Reply With Quote
Old May 23rd, 2005, 07:00 PM   #5 (permalink)
Member
 
Join Date: Apr 12th, 2004
Location: Victoria BC
Posts: 248
Default

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
);
}
}
}
mprielozny is offline  
Send a private message to mprielozny Reply With Quote
Old May 23rd, 2005, 07:01 PM   #6 (permalink)
Member
 
Join Date: Apr 12th, 2004
Location: Victoria BC
Posts: 248
Default

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);
mprielozny is offline  
Send a private message to mprielozny Reply With Quote
Old May 23rd, 2005, 07:08 PM   #7 (permalink)
Deal Addict
 
Join Date: May 24th, 2004
Location: Victoria
Posts: 1,181
Default

I need all that to display one lousy picture? yowch
__________________
I hope Life isn't one big joke because I don't get it.
Slimfast is offline  
Send a private message to Slimfast Reply With Quote
Old May 25th, 2005, 03:51 AM   #8 (permalink)
Member
 
Join Date: Apr 12th, 2004
Location: Victoria BC
Posts: 248
Default

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);
mprielozny is offline  
Send a private message to mprielozny Reply With Quote
Old May 25th, 2005, 04:48 AM   #9 (permalink)
Deal Fanatic
 
Join Date: Apr 18th, 2003
Location: Shek-O (by the beach), Hong Kong
Posts: 8,610
Send a message via ICQ to chatbox Send a message via MSN to chatbox
Default

Damn, that's still close to a dozen lines to display a pic!
chatbox is offline  
Send a private message to chatbox Reply With Quote
Old May 25th, 2005, 10:14 AM   #10 (permalink)
Sr. Member
 
fwhc022883's Avatar
 
Join Date: Nov 21st, 2002
Location: Hong Kong
Posts: 655
Default

Quote:
Originally Posted by chatbox
Damn, that's still close to a dozen lines to display a pic!
Some of those lines are just for visual enhancements such as the setBorder and the setBounds method. I just squeeze it into 4 lines.
fwhc022883 is offline  
Send a private message to fwhc022883 Reply With Quote
Old May 25th, 2005, 11:08 AM   #11 (permalink)
Deal Addict
 
Join Date: May 24th, 2004
Location: Victoria
Posts: 1,181
Default

i got it working! Thanks a lot guys!
__________________
I hope Life isn't one big joke because I don't get it.
Slimfast is offline  
Send a private message to Slimfast Reply With Quote
Old May 25th, 2005, 11:24 AM   #12 (permalink)
Deal Guru
 
deep's Avatar
 
Join Date: Nov 20th, 2002
Location: Mississauga
Posts: 12,453
Default

Quote:
Originally Posted by mprielozny
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);
Java seems so efficient suddenly.
deep is offline  
Send a private message to deep Reply With Quote
Old May 25th, 2005, 04:39 PM   #13 (permalink)
Member
 
Join Date: Apr 12th, 2004
Location: Victoria BC
Posts: 248
Default

Quote:
Originally Posted by chatbox
Damn, that's still close to a dozen lines to display a pic!

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.
mprielozny is offline  
Send a private message to mprielozny Reply With Quote
Old May 25th, 2005, 07:26 PM   #14 (permalink)
Moderator
 
temporalillusion's Avatar
 
Join Date: Jul 8th, 2001
Location: Calgary
Posts: 4,507
Default

do(whatImThinking);
temporalillusion is offline  
Send a private message to temporalillusion Reply With Quote
Old May 25th, 2005, 07:46 PM   #15 (permalink)
Deal Addict
 
Nyte's Avatar
 
Join Date: Aug 14th, 2002
Posts: 3,880
Default

Quote:
Originally Posted by Slimfast
I need all that to display one lousy picture? yowch
Thats how java is. If you want to do this stuff with less code, choose a different language, that or find some java libraries that will make it easier.
Nyte is offline  
Send a private message to Nyte Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump


All times are GMT -5. The time now is 08:32 AM.






Copyright © 2000 - RedFlagDeals.com, a division of Clear Sky Media, Inc. All rights reserved. (Terms of Use, Privacy Policy)
Close this bar

Welcome to RedFlagDeals.com - Canada's Largest Bargain Hunting Community!

If this is your first visit, the most popular forums are:

  • Hot Deals - Deals from retailers all across Canada
  • Freebies - Free samples that you can sign up for online
  • Contests - Contests from around the Internet
Sign up now!

Why join RedFlagDeals.com?

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!