#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    Help - Full screen mode in applet


    I am trying to make an applet application. By pushing a button, it opens a new frame and shows a picture and makes it full screen. this is my problem: Although it works normaly with the eclipse, when i upload it at my site, the frame is getting bigger but the picture isn't. Can anyone help me?? Thank's.

    There are the files i use:

    AppletFrame file code
    -----------------------------------

    public class AppletFrame extends JApplet implements ActionListener{
    SampleFrame sampleframe;
    JButton launchButton;

    public void init(){

    launchButton = new JButton("Open Window");
    getContentPane().add(launchButton);
    launchButton.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent arg0) {
    // TODO Auto-generated method stub
    if (sampleframe == null) {

    Image img = getImage(getCodeBase(),"background.png");
    Image img2 = getImage(getCodeBase(),"player1.png");
    sampleframe = new SampleFrame(img,img2);

    launchButton.setText("Close Window");
    sampleframe.addWindowListener(new WindowAdapter() {
    public void windowClosed(WindowEvent evt) {
    launchButton.setText("Open Window");
    launchButton.setEnabled(true);
    sampleframe = null;
    }
    });
    }

    else {
    launchButton.setEnabled(false); // disable button while waiting
    // for window to close
    sampleframe.dispose();
    }
    }

    public void destroy(){
    if (sampleframe != null) {
    sampleframe.dispose();
    sampleframe = null;
    }
    }

    } //end

    SampleFrame file code
    ----------------------------


    public class SampleFrame extends JFrame{
    Image Back;
    Image player;
    boolean runStandAlone;

    public static void main(String[] args) {

    }

    public SampleFrame(Image i1,Image i2){

    Back = i1;
    player = i2;

    setBackground( new Color(130,50,40) );

    DisplayMode displayMode;
    displayMode = new DisplayMode(800, 600, 16,
    DisplayMode.REFRESH_RATE_UNKNOWN);

    run(displayMode);

    HighLowCanvas board = new HighLowCanvas();
    getContentPane().add(board);

    }
    class HighLowCanvas extends JPanel implements ActionListener {

    String message;

    boolean gameInProgress;

    HighLowCanvas() {

    setPreferredSize(new Dimension(130,120));
    setBackground( new Color(0,120,0) );
    setForeground( Color.green );
    }

    @Override
    public void actionPerformed(ActionEvent evt) {
    // TODO Auto-generated method stub
    String command = evt.getActionCommand();
    if (command.equals("New Game"))
    repaint();
    }

    public void paintComponent(Graphics g) {

    super.paintComponent(g);
    drawCard(g, Back,player);
    }

    void drawCard(Graphics g, Image b,Image b2) {
    g.drawImage(b, 0, 0, 800, 600, this);
    g.drawImage(b2, 10, 10, 300, 250, this);
    }
    }

    private SimpleScreenManager screen;

    public void run(DisplayMode displayMode) {
    setBackground(Color.black);
    setForeground(Color.white);

    screen = new SimpleScreenManager();
    //try {
    screen.setFullScreen(displayMode, this);

    /*try {
    Thread.sleep(DEMO_TIME);
    }
    catch (InterruptedException ex) { }*/
    //}
    // finally {
    //screen.restoreScreen();
    //screen.setFullScreen(displayMode, null);
    //}
    }
    } //end

    SimpleScreenManager file code
    ---------------------------------


    public class SimpleScreenManager {
    private JFrame frame;
    private GraphicsDevice device;

    /**
    Creates a new SimpleScreenManager object.
    */
    public SimpleScreenManager() {
    GraphicsEnvironment environment =
    GraphicsEnvironment.getLocalGraphicsEnvironment();
    device = environment.getDefaultScreenDevice();
    }

    /**
    Enters full screen mode and changes the display mode.
    */
    public void setFullScreen(DisplayMode displayMode,
    JFrame window)
    {
    //device.setFullScreenWindow(window);
    //window.setSize(800, 600);
    window.setUndecorated(true);
    window.setResizable(false);
    window.setVisible(true);

    device.setFullScreenWindow(window);
    if (displayMode != null &&
    device.isDisplayChangeSupported())
    {
    try {
    device.setDisplayMode(displayMode);
    }
    catch (IllegalArgumentException ex) {
    // ignore - illegal mode for this device
    ScreenExit();
    }
    }
    }

    /**
    Returns the window currently used in full screen mode.
    */
    public Window getFullScreenWindow() {
    return device.getFullScreenWindow();
    }

    /**
    Restores the screen's display mode.
    */
    public void restoreScreen() {
    Window window = device.getFullScreenWindow();
    if (window != null) {
    window.dispose();
    ((Frame) window).setUndecorated(false);
    window.setSize(800,600);
    window.setVisible(true);
    }
    device.setFullScreenWindow(null);
    }

    public void ScreenExit(){
    Window window = device.getFullScreenWindow();
    window.dispose();
    }
    }
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

IMN logo majestic logo threadwatch logo seochat tools logo