Java Code Examples for javax.swing.JFrame#setState()

The following examples show how to use javax.swing.JFrame#setState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwingUtil.java    From Repeat with Apache License 2.0 5 votes vote down vote up
public static void focus(JFrame frame, Function<Void, Boolean> callBackRender) {
	if (frame.getState() == Frame.ICONIFIED) {
		frame.setState(Frame.NORMAL);
	}

	if (!frame.isVisible()) {
		callBackRender.apply(null);
		frame.setVisible(true);
	}

	frame.requestFocus();
	frame.toFront();
}
 
Example 2
Source File: ShakeWindow.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
    * punishes the User by moving the Chatwindow around for 10 seconds
    */
   public void startRandomMovement(final int seconds)
   {
if(window instanceof JFrame){
           JFrame f = (JFrame)window;
           f.setState(Frame.NORMAL);
           f.setVisible(true);
       }
       SparkManager.getNativeManager().flashWindow(window);
       
       final long startTime = System.currentTimeMillis()/1000L;
       
moveTimer = new Timer(5, e -> {
   Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

   double x = Math.random()*10000 % d.getWidth();
   double y = Math.random()*10000 % d.getHeight();
   int xx = Math.round(Math.round(x));
   int yy = Math.round(Math.round(y));
   window.setLocation(xx,yy);
   window.repaint();

   long now = System.currentTimeMillis()/1000L;
   long diff = now-startTime;
   System.out.println(diff);
   if(diff > seconds)
   {
       moveTimer.stop();
   }

       } );

moveTimer.start();

   }
 
Example 3
Source File: DefaultWindowController.java    From lnk2pwn with MIT License 4 votes vote down vote up
private void initBounds(JFrame frame, BoundsPolicy policy) {
    if (!EventQueue.isDispatchThread()) {
        throw new IllegalStateException("WindowController.show() should be called "
                + "from the Event Dispatch Thread.");
    }
    
    switch(policy) {
        
        case CENTER_ONLY:
            frame.setLocationRelativeTo(null);
            break;
        
        case MAXIMIZE_BOTH:
            frame.setState(JFrame.MAXIMIZED_BOTH);
            break;
            
        case PACK_ONLY:
            frame.pack();
            break;
            
        case PACK_AND_CENTER:
            frame.pack();
            frame.setLocationRelativeTo(null);
            break;
        
        case MAXIMIZE:
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            Dimension dimension = toolkit.getScreenSize();
            Insets insets = toolkit.getScreenInsets(frame.getGraphicsConfiguration());
            
            int width = dimension.width - (insets.left + insets.top);
            int height = dimension.height - (insets.top + insets.bottom);
            int x = insets.left;
            int y = insets.right;
            
            frame.pack();
            frame.setSize(width, height);
            frame.setLocation(x, y);
            
            break;
        
        case RESTORE_LAST_STATE:
            break;
        
        default:
            break;			
    }
    
}
 
Example 4
Source File: ShakeWindow.java    From Spark with Apache License 2.0 4 votes vote down vote up
public void startShake() {
    if(window instanceof JFrame){
        JFrame f = (JFrame)window;
        f.setState(Frame.NORMAL);
        f.setVisible(true);
    }
    SparkManager.getNativeManager().flashWindow(window);

    naturalLocation = window.getLocation();
    startTime = System.currentTimeMillis();
    shakeTimer =
            new Timer(SHAKE_UPDATE,
                    e -> {
                        // calculate elapsed time
                        long elapsed = System.currentTimeMillis() - startTime;
                        // use sin to calculate an x-offset
                        double waveOffset = (elapsed % SHAKE_CYCLE) /
                                SHAKE_CYCLE;
                        double angle = waveOffset * TWO_PI;

                        // offset the x-location by an amount
                        // proportional to the sine, up to
                        // shake_distance
                        int shakenX = (int)((Math.sin(angle) *
                                SHAKE_DISTANCE) +
                                naturalLocation.x);

                        int shakenY;
                        if (added) {
                            shakenY = naturalLocation.y - 10;
                            added = false;
                        }
                        else {
                            shakenY = naturalLocation.y + 10;
                            added = true;
                        }

                        window.setLocation(shakenX, shakenY);
                        window.repaint();

                        // should we stop timer?
                        if (elapsed >= SHAKE_DURATION) stopShake();
                    }
            );
    shakeTimer.start();
}