Class ViewFrame

All Implemented Interfaces:
WindowListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants

public class ViewFrame extends JFrame implements WindowListener
Convenience window (JFrame) that creates and hosts a ViewPanel for 3D rendering.

This is the simplest way to get a 3D view up and running. The frame starts maximized, enforces a minimum size of 400x400, and handles window lifecycle events (minimizing, restoring, closing) automatically.

Quick start:


 // Create a window with a 3D view
 ViewFrame frame = new ViewFrame();

 // Access the view panel to add shapes and configure the scene
 ViewPanel viewPanel = frame.getViewPanel();
 viewPanel.getRootShapeCollection().addShape(
     new WireframeCube(new Point3D(0, 0, 200), 50,
         new LineAppearance(5, Color.GREEN))
 );

 // To close programmatically:
 frame.exit();
 
See Also:
  • Constructor Details

    • ViewFrame

      public ViewFrame()
      Creates a new maximized window with a 3D view.
    • ViewFrame

      public ViewFrame(String title)
      Creates a new maximized window with a 3D view and custom title.
      Parameters:
      title - the window title to display
    • ViewFrame

      public ViewFrame(int width, int height)
      Creates a new window with a 3D view at the specified size.
      Parameters:
      width - window width in pixels, or -1 for default
      height - window height in pixels, or -1 for default
    • ViewFrame

      public ViewFrame(String title, int width, int height)
      Creates a new window with a 3D view at the specified size with a custom title.
      Parameters:
      title - the window title to display
      width - window width in pixels, or -1 for default
      height - window height in pixels, or -1 for default
  • Method Details

    • exit

      public void exit()
      Exit the application.
    • getPreferredSize

      public Dimension getPreferredSize()
      Overrides:
      getPreferredSize in class Container
    • getViewPanel

      public ViewPanel getViewPanel()
      Returns the embedded ViewPanel for adding shapes and configuring the scene.
      Returns:
      the view panel contained in this frame
    • isFullscreen

      public boolean isFullscreen()
      Returns whether the frame is currently in fullscreen exclusive mode.
      Returns:
      true if the frame is in fullscreen exclusive mode
    • setFullscreen

      public boolean setFullscreen(boolean on)
      Enters or exits fullscreen exclusive mode (FSEM).

      When entering fullscreen, the current window bounds and extended state are saved so they can be restored on exit. The frame is passed to the default screen device as the fullscreen window, which automatically removes decorations and covers the entire screen. No explicit setUndecorated() call is needed — in fact, calling it would be harmful because it requires dispose() which destroys the Canvas and its BufferStrategy.

      When exiting fullscreen, the frame is released from the screen device, decorations are restored automatically, and previous bounds/extended state are restored.

      This method is idempotent: setting fullscreen to its current value is a no-op and returns true.

      Parameters:
      on - true to enter fullscreen, false to exit fullscreen
      Returns:
      true if the state changed or was already as requested, false if the transition could not be performed (e.g. unsupported graphics device)
    • toggleFullscreen

      public boolean toggleFullscreen()
      Toggles between fullscreen exclusive mode and windowed mode.

      Equivalent to setFullscreen(!isFullscreen()).

      Returns:
      true if the toggle succeeded
      See Also:
    • windowActivated

      public void windowActivated(WindowEvent e)
      Specified by:
      windowActivated in interface WindowListener
    • windowClosed

      public void windowClosed(WindowEvent e)
      Specified by:
      windowClosed in interface WindowListener
    • windowClosing

      public void windowClosing(WindowEvent e)
      Specified by:
      windowClosing in interface WindowListener
    • windowDeactivated

      public void windowDeactivated(WindowEvent e)
      Specified by:
      windowDeactivated in interface WindowListener
    • windowDeiconified

      public void windowDeiconified(WindowEvent e)
      Repaint the view when the window is deiconified. Deiconified means that the window is restored from minimized state.
      Specified by:
      windowDeiconified in interface WindowListener
    • windowIconified

      public void windowIconified(WindowEvent e)
      Do nothing when the window is iconified. Iconified means that the window is minimized.
      Specified by:
      windowIconified in interface WindowListener
      Parameters:
      e - the event to be processed
    • windowOpened

      public void windowOpened(WindowEvent e)
      Specified by:
      windowOpened in interface WindowListener