| Javada Foto Görüntülemek Arkadaslar merhaba.Soyle bir program yazdim ama tam olarak istedigim gibi calismiyor.Amacım ileri geri butonlarına bastikca resimler arasinda gezebilmek.Program su sekilde:
import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.*;
import java.awt.*;
import java.awt.Button;
import java.awt.event.*;
import java.awt.Image;
public class LabelDemo extends JPanel {
public LabelDemo() {
JLabel label1;
setBackground(Color.lightGray);
setPreferredSize(new Dimension(1020,705));
ImageIcon icon = createImageIcon("resim1.gif",
"a pretty but meaningless splat");
//Create the first label.
label1 = new JLabel("",
icon,
JLabel.CENTER);
//Set the position of its text, relative to its icon:
label1.setVerticalTextPosition(JLabel.BOTTOM);
label1.setHorizontalTextPosition(JLabel.CENTER);
//Add the labels.
add(label1);
JPanel panel=new JPanel(new GridLayout(7,2));
Button b =new Button ("İleri");
b.setFont(new Font("İleri", Font.BOLD, 14));
Button a=new Button ("Geri");
a.setFont(new Font("Geri", Font.BOLD, 14));
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//icon =createImageIcon("resim2.gif",
// "a pretty but meaningless splat");
System.out.println("calisiyor");
}
});
add(b);
add(a);
add(panel);
}
private void printData(){
}
/** Returns an ImageIcon, or null if the path was invalid. */
protected static ImageIcon createImageIcon(String path,
String description) {
java.net.URL imgURL = LabelDemo.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL, description);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("LabelDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
LabelDemo newContentPane = new LabelDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
addActionListener bolumunde ileri tusuna basinca sadece calisiyor yaziyor (bunu test amacıyla yazmıstım) ama dosyanın icindeki diger resimlere nasil ulasacagimi bilmiyorum.
Ayrıca java ile bilgisayarda kayıtlı olan butun resim dosyalarını nasil siralatabilirim bi bilginiz var mi??
Simdiden Cok tesekkurlerrrr |