Witam,
pisze w Javie prosta przegladarke plikow graficznych i zatrzymalem sie na momencie przejscia w tryb pelnoekranowy....
Chodzi mi o to, zeby wczytac plik do programu i tam od razu przejsc na pelny ekran, a obraz zeby sie dopasowal do wielkosci ekranu.
Mozecie zerknac na kod i pomoc mi to poprawic? W tym momencie jak uruchamiam program pojawia mi sie czarny ekran....
Czesc kodu z ktora mam problem to public void FullScreen. Dodam ze Javy dopiero sie ucze...za wszelka pomoc oraz korekty kodu bylbym wdzieczny.
z gory dzieki
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package projekt;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.File;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
public class Viewer extends JFrame {
private JMenuBar menubar;
private JMenu mFile;
private JMenu mHelp;
private JMenuItem mIOpen;
private JMenuItem mIFullScreen;
private JMenuItem mIExit;
private JMenuItem mIAbout;
private JScrollPane sPPicture;
private JLabel lPicture;
private void init (){
menubar= new JMenuBar();
mFile = new JMenu ("File");
mHelp = new JMenu ("Help");
mIOpen = new JMenuItem ("Open");
mIFullScreen = new JMenuItem ("Full Screen");
mIExit = new JMenuItem ("Exit");
mIAbout = new JMenuItem ("About...");
menubar.add(mFile);
menubar.add(mHelp);
mFile.add(mIOpen);
mFile.add(mIFullScreen);
mFile.add(mIExit);
mHelp.add(mIAbout);
setJMenuBar(menubar);
setSize (500, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
lPicture = new JLabel();
Container show = getContentPane();
show.add(lPicture);
sPPicture = new JScrollPane();
sPPicture.getViewport().add(lPicture);
getContentPane().add(BorderLayout.CENTER, sPPicture);
mIOpen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Open ();
}
});
mIExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Exit();
}
});
mIAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
About ();
}
});
mIFullScreen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FullScreen();
}
});
}
public Semestr2() {
super("Image Viewer");
init();
}
public static void main(String[] args) {
new Semestr2().setVisible(true);
}
private JFileChooser fC=new JFileChooser();
private void Open() {
if(fC.showOpenDialog(this)==JFileChooser.APPROVE_OPTION) {
ImageIcon image=new ImageIcon(fC.getSelectedFile().getAbsolutePath());
lPicture.setIcon(image);
}
}
public void FullScreen() {
if(fC.showOpenDialog(this)==JFileChooser.APPROVE_OPTION) {
ImageIcon image=new ImageIcon(fC.getSelectedFile().getAbsolutePath());
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = env.getDefaultScreenDevice();
GraphicsConfiguration gc = device.getDefaultConfiguration();
final Frame mainFrame = new Frame(gc);
mainFrame.setUndecorated(true);
mainFrame.setIgnoreRepaint(true);
device.setFullScreenWindow(mainFrame);
Graphics gr=mainFrame.getGraphics();
lPicture.setIcon(image);
gr.fillRect(0,0,mainFrame.getWidth(),mainFrame.getHeight());
mainFrame.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent ev) {
mainFrame.setVisible(false);
System.exit(0);
}
});
}
}
private void Exit (){
System.exit(0);
}
private void About(){
JOptionPane.showMessageDialog(null, "Image Viewer 2011");
}
}