Results 1 to 1 of 1
  1. #1
    shqiptari is offline Member
    Join Date
    Mar 2011
    Posts
    1
    Rep Power
    0

    Default 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();		
    	}
    
    }
    This is my code, this class is called then in the mvc convert class which serves as a main.

    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

  1. How to create a network picture Using Java
    By nidhirastogi in forum AWT / Swing
    Replies: 0
    Last Post: 02-16-2011, 05:54 PM
  2. Trying to get a picture drawn on java
    By thorobred in forum New To Java
    Replies: 2
    Last Post: 02-10-2011, 04:03 AM
  3. Java slave Frame access to its owner main frame problem
    By cagdaseckin in forum New To Java
    Replies: 0
    Last Post: 12-10-2010, 11:40 AM
  4. how to send picture message using smpp in java
    By manishsuvasiya in forum New To Java
    Replies: 1
    Last Post: 11-16-2010, 06:25 AM
  5. Importing Picture into Java Code
    By swimmy101 in forum New To Java
    Replies: 1
    Last Post: 02-12-2009, 09:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •