I don't see a method called reNameTo anywhere...
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
public class FileGUI2 extends JFrame implements ActionListener{
/*Create the File Section*/
JLabel lName;
JTextField tName;
JButton button1, button2;
JTabbedPane main;
File f1;
/*Rename the File Section*/
JLabel lReName;
JTextField tReName;
JButton button3, button4;
File f2;
public FileGUI2()
{
/*Declaring the Create the File Section*/
lName = new JLabel("Name");
tName = new JTextField(10);
button1 = new JButton("Create");
button1.addActionListener(this);
button2 = new JButton("Cancel");
button2.addActionListener(this);
main = new JTabbedPane();
JPanel panel1 = new JPanel();
panel1.setLayout(new FlowLayout());
panel1.add(lName);
panel1.add(tName);
panel1.add(button1);
panel1.add(button2);
/*Declaring the Rename the File Section*/
lReName = new JLabel("Rename");
tReName = new JTextField(10);
button3 = new JButton("ReName");
button4 = new JButton("Cancel");
JPanel panel2 = new JPanel();
panel2.setLayout(new FlowLayout());
panel2.add(lReName);
panel2.add(tReName);
panel2.add(button3);
panel2.add(button4);
/*Setting up the main window*/
main.addTab("Create the File",panel1);
main.addTab("ReName the File",panel2);
JPanel mPanel = (JPanel)getContentPane();
mPanel.setLayout(new BorderLayout());
mPanel.add(main);
}
public void actionPerformed(ActionEvent ae)
{
String text = tName.getText();
if(ae.getSource().equals(button1))
{
String dirName="C:/javay/Test";
try
{
f1 = new File(dirName,text);
f1.createNewFile();
}
catch(IOException io)
{
JOptionPane.showMessageDialog(null,"Invalid");
}
JOptionPane.showMessageDialog(null,"File Created in "+dirName);
}
else if(ae.getSource().equals(button2))
{
System.exit(0);
}
}
class ReName implements ActionListener{
String ReName = tReName.getText();
public void actionPerformed(ActionEvent ae)
{
String dirName="C:/javay/Test";
if(ae.getSource().equals(button3))
{
try
{
f2 = new File(dirName,ReName);
f1.reNameTo(f2);
}
catch(IOException io)
{
}
}
else if(ae.getSource().equals(button4))
{
System.exit(0);
}
}
}
public static void main(String[]args)
{
FileGUI2 fg = new FileGUI2();
fg.setVisible(true);
fg.setSize(600,200);
fg.validate();
}
}
Hi andy. That method is hereI don't see a method called reNameTo anywhere...
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
public class FileGUI3 extends JFrame implements ActionListener{
/*Create the File Section*/
JLabel lName;
JTextField tName;
JButton button1, button2;
JTabbedPane main;
File f1;
/*Rename the File Section*/
JLabel lReName;
JTextField tReName;
JButton button3, button4;
/*Clasess references*/
ReNameClass rn = new ReNameClass();
public FileGUI3 ()
{
/*Declaring the Create the File Section*/
lName = new JLabel("Name");
tName = new JTextField(10);
button1 = new JButton("Create");
button1.addActionListener(this);
button2 = new JButton("Cancel");
button2.addActionListener(this);
main = new JTabbedPane();
JPanel panel1 = new JPanel();
panel1.setLayout(new FlowLayout());
panel1.add(lName);
panel1.add(tName);
panel1.add(button1);
panel1.add(button2);
/*Declaring the Rename the File Section*/
lReName = new JLabel("Rename");
tReName = new JTextField(10);
button3 = new JButton("ReName");
button3.addActionListener(rn);
button4 = new JButton("Cancel");
button4.addActionListener(rn);
JPanel panel2 = new JPanel();
panel2.setLayout(new FlowLayout());
panel2.add(lReName);
panel2.add(tReName);
panel2.add(button3);
panel2.add(button4);
/*Setting up the main window*/
main.addTab("Create the File",panel1);
main.addTab("ReName the File",panel2);
JPanel mPanel = (JPanel)getContentPane();
mPanel.setLayout(new BorderLayout());
mPanel.add(main);
}
public void actionPerformed(ActionEvent ae)
{
String text = tName.getText();
if(ae.getSource().equals(button1))
{
String dirName="C:/javay/Test";
try
{
f1 = new File(dirName,text);
f1.createNewFile();
}
catch(IOException io)
{
JOptionPane.showMessageDialog(null,"Invalid");
}
JOptionPane.showMessageDialog(null,"File Created in "+dirName);
}
else if(ae.getSource().equals(button2))
{
System.exit(0);
}
}
class ReNameClass implements ActionListener{
public void actionPerformed(ActionEvent ae)
{
String ReName = tReName.getText();
String dirNames="C:/javay/Test";
if(ae.getSource().equals(button3))
{
try
{
File f2 = new File(dirNames,ReName);
f1.renameTo(f2);
}
catch(Exception io)
{
JOptionPane.showMessageDialog(null,"Invalid");
}
JOptionPane.showMessageDialog(null,"Your file has been renamed to: "+ReName);
}
else if(ae.getSource().equals(button4))
{
System.exit(0);
}
}
}
public static void main(String[]args)
{
FileGUI3 fg = new FileGUI3();
fg.setVisible(true);
fg.setSize(600,200);
fg.validate();
}
}
hahaha....No worries andy. You have helped me a lot in lots of Java issues.I must be blind! Completely didn't see that![]()