Bei mir hat das bisher immer funktioniert, warum funktioniert die Screenshot methode jetzt, nicht?
[highlight=Java]
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.text.NumberFormat;
import javax.imageio.ImageIO;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.Appearance;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.TextureAttributes;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.swing.JFrame;
import javax.vecmath.Color3f;
import javax.vecmath.Color4f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.Cylinder;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.universe.SimpleUniverse;
public class Trailer_3 extends JFrame implements KeyListener
{
float pos = 0;
float pos2 = 0;
SimpleUniverse u;
static Player m_Player;
Vector3f vct;
Transform3D ViewT3D;
TransformGroup ViewTG;
Vector3f vct2;
Transform3D text;
TransformGroup Text;
static int outFileSeq = 0;
static String outFileBase = "ScreenShot.Trailer";
static NumberFormat nf = NumberFormat.getInstance();
class WindowListener extends WindowAdapter{public void windowClosing(WindowEvent e)
{
m_Player.stop();
System.exit(0); }}
public Trailer_3()
{
this.addKeyListener(this);
Toolkit tk = Toolkit.getDefaultToolkit();
final Dimension d = tk.getScreenSize();
setSize(d);
setTitle("R.a.t.r.o.t.c.p.");
setUndecorated(true);
setVisible(true);
setLayout(null);
addWindowListener(new WindowListener());
GraphicsConfiguration config1 = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas1 = new Canvas3D(config1);
canvas1.setBounds(0,0,d.width,d.height);
u = new SimpleUniverse(canvas1);
u.addBranchGraph(createSceneGraph1());
add(canvas1);
try {
m_Player = Manager.createPlayer(new File("F:/Rayman/Sound.Library/Pirates.mp3").toURL() );
} catch (NoPlayerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
m_Player.start();
warte(34500);
setVisible(false);
m_Player.stop();
}
public BranchGroup createSceneGraph1()
{
BG.compile();
return BG;
}
public static void main(String[]args)
{
try
{
new Trailer_3();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void warte(long millis){try{Thread.sleep(millis);}catch(InterruptedException e){}}
public void keyPressed(KeyEvent arg0)
{
if (arg0.getKeyCode()== KeyEvent.VK_F1)
{
BufferedImage bi = null;
try {
bi = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
} catch (HeadlessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (AWTException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
nf.setMaximumFractionDigits(10);
try {
ImageIO.write( bi, "jpg", new File("C:/R.a.t.r.o.t.c.p.-Screens/"+outFileBase + nf.format(outFileSeq++)+".jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void keyReleased(KeyEvent arg0) {}
public void keyTyped(KeyEvent arg0) {}
}
[/highlight]
[highlight=Java]
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.text.NumberFormat;
import javax.imageio.ImageIO;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.Appearance;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.TextureAttributes;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.swing.JFrame;
import javax.vecmath.Color3f;
import javax.vecmath.Color4f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.Cylinder;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.universe.SimpleUniverse;
public class Trailer_3 extends JFrame implements KeyListener
{
float pos = 0;
float pos2 = 0;
SimpleUniverse u;
static Player m_Player;
Vector3f vct;
Transform3D ViewT3D;
TransformGroup ViewTG;
Vector3f vct2;
Transform3D text;
TransformGroup Text;
static int outFileSeq = 0;
static String outFileBase = "ScreenShot.Trailer";
static NumberFormat nf = NumberFormat.getInstance();
class WindowListener extends WindowAdapter{public void windowClosing(WindowEvent e)
{
m_Player.stop();
System.exit(0); }}
public Trailer_3()
{
this.addKeyListener(this);
Toolkit tk = Toolkit.getDefaultToolkit();
final Dimension d = tk.getScreenSize();
setSize(d);
setTitle("R.a.t.r.o.t.c.p.");
setUndecorated(true);
setVisible(true);
setLayout(null);
addWindowListener(new WindowListener());
GraphicsConfiguration config1 = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas1 = new Canvas3D(config1);
canvas1.setBounds(0,0,d.width,d.height);
u = new SimpleUniverse(canvas1);
u.addBranchGraph(createSceneGraph1());
add(canvas1);
try {
m_Player = Manager.createPlayer(new File("F:/Rayman/Sound.Library/Pirates.mp3").toURL() );
} catch (NoPlayerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
m_Player.start();
warte(34500);
setVisible(false);
m_Player.stop();
}
public BranchGroup createSceneGraph1()
{
BG.compile();
return BG;
}
public static void main(String[]args)
{
try
{
new Trailer_3();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void warte(long millis){try{Thread.sleep(millis);}catch(InterruptedException e){}}
public void keyPressed(KeyEvent arg0)
{
if (arg0.getKeyCode()== KeyEvent.VK_F1)
{
BufferedImage bi = null;
try {
bi = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
} catch (HeadlessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (AWTException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
nf.setMaximumFractionDigits(10);
try {
ImageIO.write( bi, "jpg", new File("C:/R.a.t.r.o.t.c.p.-Screens/"+outFileBase + nf.format(outFileSeq++)+".jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void keyReleased(KeyEvent arg0) {}
public void keyTyped(KeyEvent arg0) {}
}
[/highlight]