Hi,
gleich vorneweg: Ich bin hier neu und hoffe, dass dies hier das richtige Unterforum ist.
Also...ich habe ein Programm geschrieben, welches eine Textdatei kopiert, zusammen mit einem zugehörigen GUI. Nichts besonderes, aber ich hätte gerne, dass der Ladevorgang in einem Extrafenster angezeigt wird. Der zugehörige Ladebalken wäre nicht das Problem, aber ich frage mich, wie ich, wenn ich auf einen Button drücke, ein neues Fenster öffne.
Ich hoffe, dass mein Problem verständlich ist.
Falls benötigt, hier der Code.
gleich vorneweg: Ich bin hier neu und hoffe, dass dies hier das richtige Unterforum ist.
Also...ich habe ein Programm geschrieben, welches eine Textdatei kopiert, zusammen mit einem zugehörigen GUI. Nichts besonderes, aber ich hätte gerne, dass der Ladevorgang in einem Extrafenster angezeigt wird. Der zugehörige Ladebalken wäre nicht das Problem, aber ich frage mich, wie ich, wenn ich auf einen Button drücke, ein neues Fenster öffne.
Ich hoffe, dass mein Problem verständlich ist.
Falls benötigt, hier der Code.
Java:
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Copymakers
{
String sourcename, destname;
BufferedReader source;
PrintWriter dest;
String line;
Copymakers(String source, String dest)
{
sourcename = source;
destname = dest;
}
public boolean openSourceFile()
{
try
{
source = new BufferedReader(new FileReader(sourcename));
return true;
}
catch (IOException iox)
{
System.out.println("Problem opening " + sourcename);
return false;
}
}
public boolean openDestinationFile()
{
try
{
dest = new PrintWriter(new BufferedWriter(new FileWriter(destname)));
return true;
}
catch (IOException iox)
{
System.out.println("Problem opening " + destname);
return false;
}
}
public void closeFiles()
{
try
{
source.close();
}
catch (IOException iox)
{
System.out.println("Problem closing " + sourcename);
}
dest.close();
}
public boolean copyFiles()
{
try
{
while((line = source.readLine()) != null)
{
dest.println(line);
}
return true;
}
catch (IOException iox)
{
System.out.println("Problem reading or writing");
return false;
}
}
}
public class copyprogramm extends JFrame implements ActionListener
{
String sources, dests;
JLabel src = new JLabel("Enter the name of the sourcefile(10 chars, .txt)");
JLabel dst = new JLabel("Enter the name of the destinationfile(10 chars, .txt)");
JTextField result = new JTextField("Give me some work");
JTextField insrc = new JTextField(14);
JTextField indst = new JTextField(14);
JButton push;
JPanel srcp = new JPanel();
JPanel dstp = new JPanel();
JPanel rstp = new JPanel();
public copyprogramm()
{
push = new JButton("Lets do it");
setTitle("Copyprogramm");
result.setEditable(false);
srcp.add(src);
srcp.add(insrc);
dstp.add(dst);
dstp.add(indst);
rstp.add(result);
rstp.add(push);
getContentPane().add(srcp);
getContentPane().add(dstp);
getContentPane().add(rstp);
push.addActionListener(this);
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
}
public void actionPerformed(ActionEvent ex)
{
String inData;
inData = insrc.getText();
sources = inData;
inData = indst.getText();
dests = inData;
Copymakers cpm = new Copymakers(sources, dests);
if (cpm.openSourceFile())
{
if (cpm.openDestinationFile())
{
if (cpm.copyFiles())
{
result.setText("Done");
}
else
result.setText("Problem at copying Files");
}
else
result.setText("Problem with Destination");
}
else
result.setText("Problem with source");
cpm.closeFiles();
}
public static void main(String[] args)
{
copyprogramm frame = new copyprogramm();
windowquit wquit = new windowquit();
frame.addWindowListener(wquit);
frame.setSize(640, 480);
frame.setVisible(true);
}
}
class windowquit extends WindowAdapter
{
public void WindowClosing(WindowEvent e)
{
System.exit(0);
}
}