mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 16:49:10 +00:00
Proper frame centering
This commit is contained in:
@@ -1,13 +1,10 @@
|
|||||||
package org.parabot.core.ui;
|
package org.parabot.core.ui;
|
||||||
|
|
||||||
import org.parabot.core.Core;
|
import java.awt.BorderLayout;
|
||||||
import org.parabot.core.forum.AccountManager;
|
import java.awt.Desktop;
|
||||||
import org.parabot.core.forum.AccountManagerAccess;
|
import java.awt.Graphics;
|
||||||
import org.parabot.core.ui.images.Images;
|
import java.awt.Graphics2D;
|
||||||
import org.parabot.core.ui.utils.SwingUtil;
|
import java.awt.RenderingHints;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.KeyAdapter;
|
import java.awt.event.KeyAdapter;
|
||||||
@@ -15,6 +12,18 @@ import java.awt.event.KeyEvent;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
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
|
* Users must login with their parabot account through this LoginUI class
|
||||||
@@ -166,7 +175,7 @@ public class LoginUI extends JFrame {
|
|||||||
this.requestFocus();
|
this.requestFocus();
|
||||||
|
|
||||||
this.setSize(255, 182);
|
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 {
|
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.
|
* Packs, centers, and shows the frame.
|
||||||
*
|
*
|
||||||
@@ -27,7 +18,7 @@ public class SwingUtil {
|
|||||||
*/
|
*/
|
||||||
public static void finalize(JFrame f) {
|
public static void finalize(JFrame f) {
|
||||||
f.pack();
|
f.pack();
|
||||||
center(f);
|
f.setLocationRelativeTo(null);
|
||||||
f.setVisible(true);
|
f.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user