Here is the sample code that can be helpful to you for the thing that you need to achieve. Try this code and you will be able to the things.
Code:
import java.io. *;
import javax.swing .*;
import java.awt.event .*;
import java.awt.Dimension;
public class extends JFrame (swing2
Public swing2 ()
(
super ("My Window");
/ *
* Management of the closing event of the screen
*
L = new WindowAdapter WindowListener () (
public void windowClosing (WindowEvent e) (
System. Exit (0);
)
)
addWindowListener (l);
JLabel jLabel1 = new JLabel ("Directory name:");
JLabel jLabel2 = new JLabel ("Name *. pdf");
JTextField nom_rep = new JTextField ("directory name");
nom_rep. setPreferredSize (new Dimension (150, 20));
JTextField f_pdf = new JTextField ("fichier_pdf");
f_pdf. setPreferredSize (new Dimension (150, 20));
/ *
* Added button
*
JButton button = new JButton ("create file");
/ *
* Adding a file selector
*
JFileChooser chooser = new JFileChooser ();
/ *
* Added panel (specify)
*
JPanel panel = new JPanel ();
panel. add (jLabel1);
panel. add (nom_rep);
panel. add (jLabel2);
/ / Panel.add (f_pdf);
panel. add (chooser);
panel. add (button);
button. addActionListener (new click (nom_rep, chooser));
/ *
* Display and dump the buffer panel?
*
setContentPane (panel);
setSize (800, 100);
setVisible (true);
)
public static void main (String [] args)
(
JFrame frame = new swing2 ();
)
)
click class implements ActionListener
(
JTextField n_rep;
JFileChooser f;
/ / String n_rep;
/ / String f;
String cmd_create;
click (JTextField c_1, c_2 JFileChooser)
(
/ / System.out.println ("You passed" + c_1 + and + c_2 + "as arguments to the object clicked");
n_rep = c_1;
f = c_2;
)
public void actionPerformed (ActionEvent e)
(
/ / System.out.println ("The button was clicked");
System. Out. System.out.println ("Here are the input values, pos:" + n_rep. GetText () + "pdf and" getSelectedFile + f (). GetName () + "");
cmd_create = "md" + n_rep. getText () + "";
System. Out. System.out.println ("Command:" + cmd_create + "");
Runtime. GetRuntime (). Exec (cmd_create);
)
)
Bookmarks