Guest User

Untitled

a guest
Jan 17th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.25 KB | None | 0 0
  1. public winInit() {
  2. super("Chatterbox - Login");
  3.  
  4. try {
  5. UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  6. } catch(ClassNotFoundException e) {
  7. } catch (InstantiationException e) {
  8. } catch (IllegalAccessException e) {
  9. } catch (UnsupportedLookAndFeelException e) {
  10. }
  11.  
  12. setSize(300,135);
  13.  
  14. pn1 = new JPanel();
  15. pn2 = new JPanel();
  16. pn3 = new JPanel();
  17.  
  18. l1 = new JLabel("Username");
  19. l2 = new JLabel("Password");
  20. l3 = new JLabel("Random text here");
  21. l4 = new JLabel("Server Address");
  22. l5 = new JLabel("No address set.");
  23.  
  24. i1 = new JTextField(10);
  25.  
  26. p1 = new JPasswordField(10);
  27.  
  28. b1 = new JButton("Connect");
  29. b2 = new JButton("Register");
  30. b3 = new JButton("Set IP");
  31.  
  32. l4.setBounds(10, 12, getDim(l4).width, getDim(l4).height);
  33. l1.setBounds(10, 35, getDim(l1).width, getDim(l1).height);
  34. l2.setBounds(10, 60, getDim(l2).width, getDim(l2).height);
  35. l3.setBounds(10, 85, getDim(l3).width, getDim(l3).height);
  36. l5.setBounds(l4.getBounds().width + 14, 12, l5.getPreferredSize().width, l5.getPreferredSize().height);
  37.  
  38. l5.setForeground(Color.gray);
  39.  
  40. i1.setBounds(getDim(l1).width + 15, 35, getDim(i1).width, getDim(i1).height);
  41. p1.setBounds(getDim(l1).width + 15, 60, getDim(p1).width, getDim(p1).height);
  42.  
  43. b1.setBounds(getDim(l1).width + getDim(i1).width + 23, 34, getDim(b2).width, getDim(b1).height - 5);
  44. b2.setBounds(getDim(l1).width + getDim(i1).width + 23, 60, getDim(b2).width, getDim(b2).height - 5);
  45. b3.setBounds(getDim(l1).width + getDim(i1).width + 23, 10, etDim(b2).width, getDim(b3).height - 5);
  46.  
  47. b1.addActionListener(clickButton);
  48. b2.addActionListener(clickButton);
  49. b3.addActionListener(clickButton);
  50.  
  51. pn1.setLayout(new FlowLayout(FlowLayout.RIGHT));
  52. pn2.setLayout(new FlowLayout(FlowLayout.RIGHT));
  53.  
  54. pn1.add(l1);
  55. pn1.add(i1);
  56. pn1.add(b1);
  57.  
  58. pn2.add(l2);
  59. pn2.add(p1);
  60. pn2.add(b2);
  61.  
  62. add(pn1);
  63. add(pn2);
  64.  
  65. }
  66.  
  67. l1 = new javax.swing.JLabel();
  68. l2 = new javax.swing.JLabel();
  69. l3 = new javax.swing.JLabel();
  70. l4 = new javax.swing.JLabel();
  71. l5 = new javax.swing.JLabel();
  72. i1 = new javax.swing.JTextField();
  73. p1 = new javax.swing.JPasswordField();
  74. b1 = new javax.swing.JButton();
  75. b2 = new javax.swing.JButton();
  76. b3 = new javax.swing.JButton();
  77.  
  78. setLayout(new java.awt.GridBagLayout());
  79.  
  80. l4.setText("Server Address");
  81. gbc = new GridBagConstraints();
  82. gbc.gridx = 0;
  83. gbc.gridy = 0;
  84. gbc.anchor = GridBagConstraints.LINE_START;
  85. gbc.insets = new java.awt.Insets(2, 2, 2, 2);
  86. add(l4, gbc);
  87.  
  88. l1.setText("Username");
  89. gbc.gridy = 1;
  90. add(l1, gbc);
  91.  
  92. l2.setText("Password");
  93. gbc.gridy = 2;
  94. add(l2, gbc);
  95.  
  96. l3.setText("Random text here");
  97. gbc.gridy = 3;
  98. add(l3, gbc);
  99.  
  100. l5.setText("No address set");
  101. gbc.gridx = 1;
  102. gbc.gridy = 0;
  103. add(l5, gbc);
  104.  
  105. i1.setColumns(12);
  106. gbc.gridy = 1;
  107. add(i1, gbc);
  108.  
  109. p1.setColumns(12);
  110. gbc.gridy = 2;
  111. add(p1, gbc);
  112.  
  113. b3.setText("Set IP");
  114. gbc.gridx = 2;
  115. gbc.gridy = 0;
  116. add(b3, gbc);
  117.  
  118. b1.setText("Connect");
  119. gbc.gridx = 2;
  120. gbc.gridy = 1;
  121. add(b1, gbc);
  122.  
  123. b2.setText("Register");
  124. gbc.gridy = 2;
  125. add(b2, gbc);
  126.  
  127. import java.awt.BorderLayout;
  128. public class loginBox extends JDialog {
  129.  
  130. private final JPanel contentPanel = new JPanel();
  131. private JTextField txtUserName;
  132. private JPasswordField passwordField;
  133. private JTextField textField;
  134.  
  135. /**
  136. * Launch the application.
  137. */
  138. public static void main(String[] args) {
  139. try {
  140. loginBox dialog = new loginBox();
  141. dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
  142. dialog.setVisible(true);
  143. } catch (Exception e) {
  144. e.printStackTrace();
  145. }
  146. }
  147.  
  148. /**
  149. * Create the dialog.
  150. */
  151. public loginBox() {
  152. setBounds(100, 100, 450, 300);
  153. getContentPane().setLayout(new BorderLayout());
  154. contentPanel.setBorder(new TitledBorder(null, "Log In", TitledBorder.LEADING, TitledBorder.TOP, null, null));
  155. getContentPane().add(contentPanel, BorderLayout.CENTER);
  156. contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
  157. {
  158. JPanel panel = new JPanel();
  159. contentPanel.add(panel);
  160. panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
  161. {
  162. JLabel lblChatterBoxlogin = new JLabel("Chatter Box-Login");
  163. panel.add(lblChatterBoxlogin);
  164. }
  165. }
  166. {
  167. JPanel formPanel = new JPanel();
  168. contentPanel.add(formPanel);
  169. GridBagLayout gbl_formPanel = new GridBagLayout();
  170. gbl_formPanel.columnWidths = new int[]{52, 0, 0, 0};
  171. gbl_formPanel.rowHeights = new int[]{14, 0, 0, 0, 0, 0};
  172. gbl_formPanel.columnWeights = new double[]{0.0, 1.0, 1.0, Double.MIN_VALUE};
  173. gbl_formPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  174. formPanel.setLayout(gbl_formPanel);
  175. {
  176. JLabel lblUserName = new JLabel("User Name");
  177. GridBagConstraints gbc_lblUserName = new GridBagConstraints();
  178. gbc_lblUserName.anchor = GridBagConstraints.WEST;
  179. gbc_lblUserName.insets = new Insets(0, 0, 5, 5);
  180. gbc_lblUserName.gridx = 0;
  181. gbc_lblUserName.gridy = 0;
  182. formPanel.add(lblUserName, gbc_lblUserName);
  183. }
  184. {
  185. txtUserName = new JTextField();
  186. GridBagConstraints gbc_txtUserName = new GridBagConstraints();
  187. gbc_txtUserName.insets = new Insets(0, 0, 5, 5);
  188. gbc_txtUserName.fill = GridBagConstraints.HORIZONTAL;
  189. gbc_txtUserName.gridx = 1;
  190. gbc_txtUserName.gridy = 0;
  191. formPanel.add(txtUserName, gbc_txtUserName);
  192. txtUserName.setColumns(10);
  193. }
  194. {
  195. JLabel lblPassword = new JLabel("Password");
  196. GridBagConstraints gbc_lblPassword = new GridBagConstraints();
  197. gbc_lblPassword.anchor = GridBagConstraints.WEST;
  198. gbc_lblPassword.insets = new Insets(0, 0, 5, 5);
  199. gbc_lblPassword.gridx = 0;
  200. gbc_lblPassword.gridy = 1;
  201. formPanel.add(lblPassword, gbc_lblPassword);
  202. }
  203. {
  204. passwordField = new JPasswordField();
  205. GridBagConstraints gbc_passwordField = new GridBagConstraints();
  206. gbc_passwordField.insets = new Insets(0, 0, 5, 5);
  207. gbc_passwordField.fill = GridBagConstraints.HORIZONTAL;
  208. gbc_passwordField.gridx = 1;
  209. gbc_passwordField.gridy = 1;
  210. formPanel.add(passwordField, gbc_passwordField);
  211. }
  212. {
  213. JLabel lblServer = new JLabel("Server Address");
  214. GridBagConstraints gbc_lblServer = new GridBagConstraints();
  215. gbc_lblServer.anchor = GridBagConstraints.ABOVE_BASELINE_TRAILING;
  216. gbc_lblServer.insets = new Insets(0, 0, 5, 5);
  217. gbc_lblServer.gridx = 0;
  218. gbc_lblServer.gridy = 2;
  219. formPanel.add(lblServer, gbc_lblServer);
  220. }
  221. {
  222. textField = new JTextField();
  223. GridBagConstraints gbc_textField = new GridBagConstraints();
  224. gbc_textField.insets = new Insets(0, 0, 5, 5);
  225. gbc_textField.fill = GridBagConstraints.HORIZONTAL;
  226. gbc_textField.gridx = 1;
  227. gbc_textField.gridy = 2;
  228. formPanel.add(textField, gbc_textField);
  229. textField.setColumns(10);
  230. }
  231. {
  232. JLabel lblNoAddressSet = new JLabel("No Address Set");
  233. GridBagConstraints gbc_lblNoAddressSet = new GridBagConstraints();
  234. gbc_lblNoAddressSet.insets = new Insets(0, 0, 5, 0);
  235. gbc_lblNoAddressSet.gridx = 2;
  236. gbc_lblNoAddressSet.gridy = 2;
  237. formPanel.add(lblNoAddressSet, gbc_lblNoAddressSet);
  238. }
  239. {
  240. JLabel lblRandomTextHere = new JLabel("Random Text Here");
  241. GridBagConstraints gbc_lblRandomTextHere = new GridBagConstraints();
  242. gbc_lblRandomTextHere.insets = new Insets(0, 0, 5, 5);
  243. gbc_lblRandomTextHere.gridx = 1;
  244. gbc_lblRandomTextHere.gridy = 3;
  245. formPanel.add(lblRandomTextHere, gbc_lblRandomTextHere);
  246. }
  247. }
  248. {
  249. JPanel buttonPane = new JPanel();
  250. buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
  251. getContentPane().add(buttonPane, BorderLayout.SOUTH);
  252. {
  253. JButton okButton = new JButton("Connect");
  254. okButton.setActionCommand("OK");
  255. buttonPane.add(okButton);
  256. getRootPane().setDefaultButton(okButton);
  257. }
  258. {
  259. JButton btnNewButton = new JButton("Register");
  260. buttonPane.add(btnNewButton);
  261. }
  262. {
  263. JButton btnNewButton_1 = new JButton("Set IP");
  264. buttonPane.add(btnNewButton_1);
  265. }
  266. {
  267. JButton cancelButton = new JButton("Cancel");
  268. cancelButton.setActionCommand("Cancel");
  269. buttonPane.add(cancelButton);
  270. }
  271. }
  272. }
  273.  
  274. }
Add Comment
Please, Sign In to add comment