The Artima Developer Community
Sponsored Link

Java Answers Forum
Pictures

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Mira

Posts: 3
Nickname: mizza
Registered: Mar, 2003

Pictures Posted: Apr 8, 2003 4:59 AM
Reply to this message Reply
Advertisement
I'm trying to make a program which will which will allow me 2 switch between a number of pictures "opera.jpg", "nbeach.jpg", "bridge.jpg", when the Load button is pressed, however i don't know how to make it do that, not properly. Any ideas? I want to be able to tell which picture is currently shown and change it to the next in alphabetical order.


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
 
class Photo{
	public static void main(String[] args){
	    MyFrame frame = new MyFrame();
		frame.setSize(400,300);
        frame.setVisible(true);
	  }
}
 
 
class MyFrame extends JFrame implements ActionListener{
 
ImgPanel panel;
 
    public MyFrame(){
 
	    getContentPane().setLayout(new BorderLayout());
 
	    JButton button = new JButton("Load");
	    JPanel panel2 = new JPanel();
	    panel2.add(button);
 		getContentPane().add(panel2, BorderLayout.SOUTH);
 
        panel = new ImgPanel();
        getContentPane().add(panel, BorderLayout.CENTER);
        panel.setVisible(true);
		button.addActionListener(this);
   }
 
    public void actionPerformed(ActionEvent evt){
        panel.setVisible(true);
   }
 
}
 
 
class ImgPanel extends JPanel{
 
    private Image image;
    public ImgPanel(){
		image = Toolkit.getDefaultToolkit().getImage("opera.jpg");
	}
 
    public void paintComponent(Graphics g){
		super.paintComponent(g);
        g.drawImage(image, 30, 30, this);
    }
}

Topic: package Previous Topic   Next Topic Topic: Console mode clear screen...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use