Results 1 to 1 of 1
Thread: Java Picture Frame ???
- 03-30-2011, 01:02 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 1
- Rep Power
- 0
Java Picture Frame ???
Hello,
I am new to Java, but I need to implement a an mvc program to display some temperature gui. Also I want to Display 4 pic to show the seasons based on temperature range,
I am having trouble with this thing, because it just shows the first picture
Java Code:import java.awt.*; import java.awt.event.*; import java.util.Observable; import java.util.Observer; @SuppressWarnings("serial") public class DisplayPic extends Frame implements Observer { private TemperatureModel model; private Image img; private String imagePath = null; private int temperatureF; public DisplayPic(TemperatureModel model, int h, int v) { super("Image Frame"); this.model = model; int temperatureF = (int) model().getF(); if (temperatureF <= 40) imagePath = "winter.gif"; else if (temperatureF > 40 && temperatureF <= 80) imagePath = "spring.gif"; else if (temperatureF > 80 && temperatureF <= 140) imagePath = "fall.gif"; else imagePath = "summer.gif"; MediaTracker mt = new MediaTracker(null); img = Toolkit.getDefaultToolkit().getImage(imagePath); mt.addImage(img, 0); setSize(400, 400); setVisible(true); model.addObserver(this); // Connect to the model addWindowListener(new TemperatureGUI.CloseListener()); } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { temperatureF = (int) model().getF(); if (img != null) g.drawImage(img, 100, 100, null); else g.clearRect(0, 0, getSize().width, getSize().height); super.paint(g); } protected TemperatureModel model() { return model; } @Override public void update(Observable obs, Object o) { repaint(); } }
I want to change the picture with respect to the specified ranges,
but the problem is that for some reason when the user changes the pic in the scree this is not updated in the program, does it have to do with the implementation of any Listener, BTW model().getF() always changes when the temp changes ( it takes the temperature)Last edited by Fubarable; 03-30-2011 at 02:54 AM. Reason: quote tags changed to code tags
Similar Threads
-
How to create a network picture Using Java
By nidhirastogi in forum AWT / SwingReplies: 0Last Post: 02-16-2011, 05:54 PM -
Trying to get a picture drawn on java
By thorobred in forum New To JavaReplies: 2Last Post: 02-10-2011, 04:03 AM -
Java slave Frame access to its owner main frame problem
By cagdaseckin in forum New To JavaReplies: 0Last Post: 12-10-2010, 11:40 AM -
how to send picture message using smpp in java
By manishsuvasiya in forum New To JavaReplies: 1Last Post: 11-16-2010, 06:25 AM -
Importing Picture into Java Code
By swimmy101 in forum New To JavaReplies: 1Last Post: 02-12-2009, 09:48 AM
Bookmarks