mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-04 16:49:10 +00:00
Proper frame centering
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
package org.parabot.core.ui;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.forum.AccountManager;
|
||||
import org.parabot.core.forum.AccountManagerAccess;
|
||||
import org.parabot.core.ui.images.Images;
|
||||
import org.parabot.core.ui.utils.SwingUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Desktop;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
@@ -15,6 +12,18 @@ import java.awt.event.KeyEvent;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.forum.AccountManager;
|
||||
import org.parabot.core.forum.AccountManagerAccess;
|
||||
import org.parabot.core.ui.images.Images;
|
||||
|
||||
/**
|
||||
*
|
||||
* Users must login with their parabot account through this LoginUI class
|
||||
@@ -166,7 +175,7 @@ public class LoginUI extends JFrame {
|
||||
this.requestFocus();
|
||||
|
||||
this.setSize(255, 182);
|
||||
SwingUtil.center(this);
|
||||
this.setLocationRelativeTo(null);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package org.parabot.core.ui.utils;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Toolkit;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds various awt util based methods
|
||||
*
|
||||
* @author Dane
|
||||
*
|
||||
*/
|
||||
public class AwtUtil {
|
||||
private static Toolkit toolkit;
|
||||
|
||||
public static Toolkit getToolkit() {
|
||||
if (toolkit == null) {
|
||||
toolkit = Toolkit.getDefaultToolkit();
|
||||
}
|
||||
return toolkit;
|
||||
}
|
||||
|
||||
public static Dimension getScreenSize() {
|
||||
return AwtUtil.getToolkit().getScreenSize();
|
||||
}
|
||||
|
||||
public static int getScreenWidth() {
|
||||
return AwtUtil.getScreenSize().width;
|
||||
}
|
||||
|
||||
public static int getScreenHeight() {
|
||||
return AwtUtil.getScreenSize().height;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,15 +11,6 @@ import javax.swing.JFrame;
|
||||
*/
|
||||
public class SwingUtil {
|
||||
|
||||
/**
|
||||
* Centers the frame.
|
||||
*
|
||||
* @param f
|
||||
*/
|
||||
public static void center(JFrame f) {
|
||||
f.setLocation((AwtUtil.getScreenWidth() - f.getWidth()) / 2, (AwtUtil.getScreenHeight() - f.getHeight()) / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Packs, centers, and shows the frame.
|
||||
*
|
||||
@@ -27,7 +18,7 @@ public class SwingUtil {
|
||||
*/
|
||||
public static void finalize(JFrame f) {
|
||||
f.pack();
|
||||
center(f);
|
||||
f.setLocationRelativeTo(null);
|
||||
f.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user