열심히 포스팅 했더니 완전 간략한 방법이 있었다 출처 : [java] 프레임 스크린 중앙에 배치하기 단 한줄 코딩 frame.setLocationRelativeTo(null); 하지만 아직 듀얼모니터 환경에서는 아래 내가 작성한 방법대로 해야하지 않을까? 뭔가 짧고 간결하면서도 정확 명확 그런글이 발견될때까지 일단 그대로 두기로 한다 실행하게 될 어떤 컴퓨터건 그 해당 컴퓨터의 화면 정 중앙에 프로그렘을 띄워준다 다중모니터인경우 첫 모니터의 중앙에 띄워주도록 작성했다. GraphicsEnvironment, GraphicsDevice 를 사용한다 작성 코드는 다음과 같다. https://developer-salieri.tistory.com/185 위 링크의 소스을 가져다 놓고 class PanelChangeExample 를 수정하였다. 띄어지게될 모니터 크기의 1/4 크기로 띄워지게 된다 작성 끝 요즘 자바 GUI를 이용해서 게임 서버 관리툴을 만들고 있습니다. 요즘은 관리툴을 모두 웹으로 만들고 있는 추세이지만, 일정이 촉박하여 아무래도 손에 제일 익은 자바로 후딱 만들고 있어요 ^^ 자바 스윙을 이용해서 메인 Frame을 생성하면 화면의 좌측 상단에서 부터 창이 생깁니다. 멋없죠 '- ' ;;; 화면 가운데 띄우고 싶어서 이것 저것 찾아보고 메모차원에서 남겨둡니다.
이렇게 하면 끝 ^ㅡ^ 참 쉽죠? //창띄우기실습 import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JButton; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class JOptionPaneExextends JFrame { private JPanel contentPane; /** * Launch the application. */ publicstaticvoid main(String[] args) { EventQueue.invokeLater(new Runnable() { publicvoid run() { try { JOptionPaneEx frame = new JOptionPaneEx(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public JOptionPaneEx() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JButton btnNewButton = new JButton("New button"); btnNewButton.addMouseListener(new MouseAdapter() { @Override publicvoid mouseClicked(MouseEvent arg0) { // JOptionPane.showMessageDialog(JOptionPaneEx.this, "메세지", "타이틀", JOptionPane.INFORMATION_MESSAGE); //메세지창띄우기 // int flag = JOptionPane.showConfirmDialog(JOptionPaneEx.this, "메세지", "타이틀!", JOptionPane.YES_NO_OPTION);//리턴값이있음 // System.out.println(flag);
// String flag = JOptionPane.showInputDialog(JOptionPaneEx.this, "메세지", "타이틀!", JOptionPane.YES_NO_OPTION);//입력받을수있음 // System.out.println(flag);
String[] buttonName = {"로그인", "회원가입"}; int flag = JOptionPane.showOptionDialog(JOptionPaneEx.this, "메세지", "타이틀", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, buttonName, buttonName[0]); System.out.println(flag); } }); btnNewButton.setBounds(12, 10, 410, 23); contentPane.add(btnNewButton); } } |