Skip to content

Commit 22c2bb2

Browse files
committed
jDialog Add Server in separate file + optimizations
1 parent 9ddd026 commit 22c2bb2

4 files changed

Lines changed: 349 additions & 229 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
4+
<Properties>
5+
<Property name="defaultCloseOperation" type="int" value="2"/>
6+
<Property name="title" type="java.lang.String" value="Add Server"/>
7+
<Property name="location" type="java.awt.Point" editor="org.netbeans.beaninfo.editors.PointEditor">
8+
<Point value="[0, 0]"/>
9+
</Property>
10+
<Property name="resizable" type="boolean" value="false"/>
11+
</Properties>
12+
<SyntheticProperties>
13+
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
14+
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
15+
</SyntheticProperties>
16+
<AuxValues>
17+
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
18+
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
19+
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
20+
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
21+
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
22+
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
23+
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
24+
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
25+
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
26+
</AuxValues>
27+
28+
<Layout>
29+
<DimensionLayout dim="0">
30+
<Group type="103" groupAlignment="0" attributes="0">
31+
<Group type="102" attributes="0">
32+
<EmptySpace pref="54" max="32767" attributes="0"/>
33+
<Group type="103" groupAlignment="0" attributes="0">
34+
<Component id="jTxtAdd" alignment="0" min="-2" pref="293" max="-2" attributes="0"/>
35+
<Component id="jLblAdd" alignment="0" max="32767" attributes="0"/>
36+
</Group>
37+
<EmptySpace pref="54" max="32767" attributes="0"/>
38+
</Group>
39+
<Group type="102" alignment="1" attributes="0">
40+
<EmptySpace max="32767" attributes="0"/>
41+
<Component id="jBtnAdd" min="-2" pref="171" max="-2" attributes="0"/>
42+
<EmptySpace max="32767" attributes="0"/>
43+
</Group>
44+
</Group>
45+
</DimensionLayout>
46+
<DimensionLayout dim="1">
47+
<Group type="103" groupAlignment="0" attributes="0">
48+
<Group type="102" alignment="1" attributes="0">
49+
<EmptySpace max="32767" attributes="0"/>
50+
<Component id="jLblAdd" min="-2" pref="21" max="-2" attributes="0"/>
51+
<EmptySpace type="unrelated" max="32767" attributes="0"/>
52+
<Component id="jTxtAdd" min="-2" pref="25" max="-2" attributes="0"/>
53+
<EmptySpace pref="12" max="32767" attributes="0"/>
54+
<Component id="jBtnAdd" min="-2" max="-2" attributes="0"/>
55+
<EmptySpace max="32767" attributes="0"/>
56+
</Group>
57+
</Group>
58+
</DimensionLayout>
59+
</Layout>
60+
<SubComponents>
61+
<Component class="javax.swing.JTextField" name="jLblAdd">
62+
<Properties>
63+
<Property name="editable" type="boolean" value="false"/>
64+
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
65+
<Color blue="df" green="d9" red="d6" type="rgb"/>
66+
</Property>
67+
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
68+
<Color blue="0" green="0" red="0" type="rgb"/>
69+
</Property>
70+
<Property name="horizontalAlignment" type="int" value="0"/>
71+
<Property name="text" type="java.lang.String" value="Intraduce the server IP (with port if different)"/>
72+
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
73+
<Border info="null"/>
74+
</Property>
75+
</Properties>
76+
</Component>
77+
<Component class="javax.swing.JTextField" name="jTxtAdd">
78+
<Properties>
79+
<Property name="horizontalAlignment" type="int" value="0"/>
80+
<Property name="text" type="java.lang.String" value="myserverminecraft.ddns.net:24321"/>
81+
</Properties>
82+
</Component>
83+
<Component class="javax.swing.JButton" name="jBtnAdd">
84+
<Properties>
85+
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
86+
<Color blue="33" green="cc" red="0" type="rgb"/>
87+
</Property>
88+
<Property name="text" type="java.lang.String" value="Add server"/>
89+
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
90+
<Color id="Cursor de Mano"/>
91+
</Property>
92+
</Properties>
93+
<Events>
94+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jBtnAddActionPerformed"/>
95+
</Events>
96+
</Component>
97+
</SubComponents>
98+
</Form>
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
/*
2+
* This file is part of StatusMCServerTool.
3+
*
4+
* StatusMCServerTool is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* StatusMCServerTool is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with StatusMCServerTool. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
package com.devparada.frame;
18+
19+
import javax.swing.JOptionPane;
20+
21+
/**
22+
*
23+
* @author devparada
24+
*/
25+
public class AddServerDialog extends javax.swing.JDialog {
26+
27+
private final InitFrame jFrame;
28+
29+
/**
30+
* Saves the host and ip of dialog
31+
*/
32+
private String HostIpDialog;
33+
34+
/**
35+
* Creates new form AddServerDialog
36+
*
37+
* @param parent
38+
* @param modal
39+
*/
40+
public AddServerDialog(java.awt.Frame parent, boolean modal) {
41+
super(parent, modal);
42+
initComponents();
43+
jFrame = (InitFrame) parent;
44+
}
45+
46+
public String getHostIpDialog() {
47+
return HostIpDialog;
48+
}
49+
50+
public void setHostIpDialog(String HostIpDialog) {
51+
this.HostIpDialog = HostIpDialog;
52+
}
53+
54+
/**
55+
* This method is called from within the constructor to initialize the form.
56+
* WARNING: Do NOT modify this code. The content of this method is always
57+
* regenerated by the Form Editor.
58+
*/
59+
@SuppressWarnings("unchecked")
60+
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
61+
private void initComponents() {
62+
63+
jLblAdd = new javax.swing.JTextField();
64+
jTxtAdd = new javax.swing.JTextField();
65+
jBtnAdd = new javax.swing.JButton();
66+
67+
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
68+
setTitle("Add Server");
69+
setLocation(new java.awt.Point(0, 0));
70+
setResizable(false);
71+
72+
jLblAdd.setEditable(false);
73+
jLblAdd.setBackground(new java.awt.Color(214, 217, 223));
74+
jLblAdd.setForeground(new java.awt.Color(0, 0, 0));
75+
jLblAdd.setHorizontalAlignment(javax.swing.JTextField.CENTER);
76+
jLblAdd.setText("Intraduce the server IP (with port if different)");
77+
jLblAdd.setBorder(null);
78+
79+
jTxtAdd.setHorizontalAlignment(javax.swing.JTextField.CENTER);
80+
jTxtAdd.setText("myserverminecraft.ddns.net:24321");
81+
82+
jBtnAdd.setBackground(new java.awt.Color(0, 204, 51));
83+
jBtnAdd.setText("Add server");
84+
jBtnAdd.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
85+
jBtnAdd.addActionListener(new java.awt.event.ActionListener() {
86+
public void actionPerformed(java.awt.event.ActionEvent evt) {
87+
jBtnAddActionPerformed(evt);
88+
}
89+
});
90+
91+
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
92+
getContentPane().setLayout(layout);
93+
layout.setHorizontalGroup(
94+
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
95+
.addGroup(layout.createSequentialGroup()
96+
.addContainerGap(54, Short.MAX_VALUE)
97+
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
98+
.addComponent(jTxtAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
99+
.addComponent(jLblAdd))
100+
.addContainerGap(54, Short.MAX_VALUE))
101+
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
102+
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
103+
.addComponent(jBtnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
104+
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
105+
);
106+
layout.setVerticalGroup(
107+
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
108+
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
109+
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
110+
.addComponent(jLblAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
111+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
112+
.addComponent(jTxtAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
113+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
114+
.addComponent(jBtnAdd)
115+
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
116+
);
117+
118+
pack();
119+
}// </editor-fold>//GEN-END:initComponents
120+
121+
private void jBtnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnAddActionPerformed
122+
this.setHostIpDialog(jTxtAdd.getText());
123+
124+
if (checkAddDialog()) {
125+
String[] ipServerArray = getHostIpDialog().split(":");
126+
int port = 25565;
127+
128+
String serverIp = getHostIpDialog();
129+
jTxtAdd.setText("");
130+
131+
if (ipServerArray.length == 2) {
132+
port = Integer.parseInt(ipServerArray[1]);
133+
} else {
134+
serverIp = getHostIpDialog() + ":" + port;
135+
}
136+
137+
this.setVisible(false);
138+
jFrame.database.addRow(serverIp);
139+
jFrame.addPanel(ipServerArray[0], port);
140+
} else {
141+
this.setVisible(true);
142+
}
143+
}//GEN-LAST:event_jBtnAddActionPerformed
144+
145+
/**
146+
* Check the JTextField the dialog of dialog add server of the database
147+
*
148+
* @return Return true if checks are correct
149+
*/
150+
private boolean checkAddDialog() {
151+
String JTxtText = getHostIpDialog();
152+
153+
if (JTxtText.length() != 0) {
154+
String[] ipServerArray = JTxtText.split(":");
155+
156+
// \\d+ -> only numbers
157+
if (ipServerArray.length == 2 && !ipServerArray[1].matches("\\d+")) {
158+
JOptionPane.showMessageDialog(this, "Port not is number", "Error Add Server", JOptionPane.WARNING_MESSAGE);
159+
} else if (ipServerArray.length == 2 && ipServerArray[1].matches("\\d+")) {
160+
return true;
161+
} else {
162+
return true;
163+
}
164+
} else {
165+
JOptionPane.showMessageDialog(this, "IP Server not blank", "Error Add Server", JOptionPane.WARNING_MESSAGE);
166+
}
167+
return false;
168+
}
169+
170+
/**
171+
* @param args the command line arguments
172+
*/
173+
public static void main(String args[]) {
174+
/* Set the Nimbus look and feel */
175+
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
176+
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
177+
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
178+
*/
179+
try {
180+
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
181+
if ("Nimbus".equals(info.getName())) {
182+
javax.swing.UIManager.setLookAndFeel(info.getClassName());
183+
break;
184+
}
185+
}
186+
} catch (ClassNotFoundException ex) {
187+
java.util.logging.Logger.getLogger(AddServerDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
188+
} catch (InstantiationException ex) {
189+
java.util.logging.Logger.getLogger(AddServerDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
190+
} catch (IllegalAccessException ex) {
191+
java.util.logging.Logger.getLogger(AddServerDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
192+
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
193+
java.util.logging.Logger.getLogger(AddServerDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
194+
}
195+
//</editor-fold>
196+
197+
/* Create and display the dialog */
198+
java.awt.EventQueue.invokeLater(new Runnable() {
199+
@Override
200+
public void run() {
201+
AddServerDialog dialog = new AddServerDialog(new javax.swing.JFrame(), true);
202+
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
203+
@Override
204+
public void windowClosing(java.awt.event.WindowEvent e) {
205+
System.exit(0);
206+
}
207+
});
208+
dialog.setVisible(true);
209+
}
210+
});
211+
}
212+
213+
// Variables declaration - do not modify//GEN-BEGIN:variables
214+
private javax.swing.JButton jBtnAdd;
215+
private javax.swing.JTextField jLblAdd;
216+
private javax.swing.JTextField jTxtAdd;
217+
// End of variables declaration//GEN-END:variables
218+
}

0 commit comments

Comments
 (0)