Package Com.matp.view;
Import Java.awt.FlowLayout;
public class Simpledialog extends JDialog implements ActionListener {
text box for entering a string
JTextField field;
JTextField Field2;
The parent form of the dialog box.
Recordtestcasewin parent;
"OK" button
JButton Setbutton;
/**
* Constructors, parameters are the caption of the parent form and the dialog box
*/
Public Simpledialog (JFrame Prentframe, String title) {
Call the constructor of the parent class,
The third argument with false means that other forms are allowed to be activated. True indicates that no other form can be activated
Super (Prentframe, title, false);
Parent = (Recordtestcasewin) prentframe;
Add a label and enter a text box
JPanel P1 = new JPanel ();
JLabel label = new JLabel ("Please enter project name:");
P1.add (label);
field = new JTextField (30);
Field.addactionlistener (this);
P1.add (field);
Getcontentpane (). Add ("North", p1);
Add a label and enter a text box
JPanel p3 = new JPanel ();
JLabel Label2 = new JLabel ("Please enter script name:");
P3.add (Label2);
Field2 = new JTextField (30);
Field2.addactionlistener (this);
P3.add (Field2);
Getcontentpane (). Add ("Center", p3);
Add OK and Cancel buttons
JPanel P2 = new JPanel ();
P2.setlayout (New FlowLayout (flowlayout.right));
JButton CancelButton = new JButton ("Cancel");
Cancelbutton.addactionlistener (this);
Setbutton = new JButton ("OK");
Setbutton.addactionlistener (this);
P2.add (Setbutton);
P2.add (CancelButton);
Getcontentpane (). Add ("South", p2);
Resize dialog box layout
Pack ();
}
/**
* Event Handling
*/
public void actionperformed (ActionEvent event) {
Object Source = Event.getsource ();
if ((Source = = Setbutton)) {
If the OK button is pressed, the text of the text mine is added to the text field of the parent form
Parent.settext (Field.gettext ());
File F = new file (". \\config\\save\\shutter_button.txt");
File FW = new file ("D:\\matp_robot");
String txtname = Field.gettext ();
File file3 =new file ("D:\\matp_robot" + "\ \" + txtname);
If the folder does not exist, create
if (!file3. Exists () &&!file3. Isdirectory ())
{
SYSTEM.OUT.PRINTLN ("//Not Present");
File3. mkdir ();
} else
{
SYSTEM.OUT.PRINTLN ("//Directory Exists");
}
File File = new file (". \\config\\batfolder\\Matp.bat");
if (file.exists ()) {
File.delete ();
}
BufferedWriter writer = null;
try {
writer = new BufferedWriter (New FileWriter (
". \\config\\batfolder\\Save.bat", true));
} catch (IOException E2) {
TODO auto-generated Catch block
E2.printstacktrace ();
}
try {
Writer.write ("echo off" + "\ r \ n");
Writer.write ("copy. \\config\\shutter_button.txt" + "D:\\matp_robot" + "\ \" +txtname
+ "\ r \ n");
Writer.flush ();
Writer.close ();
} catch (IOException E1) {
TODO auto-generated Catch block
E1.printstacktrace ();
}
Ramthreadon Mramthreadon = new Ramthreadon ();
Mramthreadon.run ();
String Txtname2 = Field2.gettext ();
File F = new file ("d:\\matp_robot\\" + "\ \" +txtname+ "\ \" + "Shutter_button.txt");
System.out.println (f);
F.renameto (New File ("d:\\matp_robot\\" + "\ \" +txtname+ "\ \" + Txtname2 + ". txt"));
System.out.println (f + "========11========");
Joptionpane.showmessagedialog (NULL, "script saved in D:\\matp_robot" + "\ \" +txtname+ "directory");
Field2.settext ("");
}
Field.selectall ();
Hide dialog box
SetVisible (FALSE);
}
}
Call class
Exportbtn.addactionlistener (new ActionListener () {
@Override
public void actionperformed (ActionEvent arg0) {
Ramthreadon Mramthreadon = new Ramthreadon ();
Mramthreadon.run ();
String txtname = Filename.gettext ();
File F = new file (". \\config\\save\\shutter_button.txt");
File F = new file (". \\config\\save\\shutter_button.txt");
System.out.println (f);
F.renameto (New File (". \\config\\save\\" + txtname + ". txt"));
System.out.println (f + "========11========");
Joptionpane.showmessagedialog (NULL, "script saved in Config\\save directory");
Filename.settext ("");
if (dialog = = null) {
dialog = new Simpledialog (prentframe, "VCV");
}
Dialog.setvisible (TRUE);
Dialog.setlocation (500, 400);
//
}
});
Java Customization dialog box