-
Help please?
I was writing a tool in Java using Swing for the GUI, and it just randomly started to throw an error about not being able to find the buttons...
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* MultiMCManagerGUI.java
*
* Created on Oct 31, 2011, 1:12:49 AM
*/
package mcmultimanager;
import java.io.*;
/**
*
* @author Dominic
*/
public class MultiMCManagerGUI extends javax.swing.JDialog {
/** Creates new form MultiMCManagerGUI */
public MultiMCManagerGUI(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jButton1.setText("Minecraft1");
jButton1.setToolTipText("");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Minecraft2");
jLabel1.setToolTipText("");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2))
.addComponent(jLabel1))
.addContainerGap(218, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1)
.addContainerGap(251, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
MultiMCManagerGUI dialog = new MultiMCManagerGUI(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
if (!System.getProperty("os.name").startsWith("Windows")){
System.exit(0);}
File mcdirectory = new File(System.getenv("APPDATA") + "/MCMultiManager");
if (!mcdirectory.exists()){
mcdirectory.mkdir();
File defaultmc = new File(mcdirectory + "/1");
defaultmc.mkdir();
File oldmc = new File(System.getenv("APPDATA") + "/.minecraft");
try{
copyFolder(oldmc,defaultmc);
}catch(IOException e){
e.printStackTrace();
//error, just exit
System.exit(0);
}
System.out.println("Done copying");
oldmc.delete();}
}
public static void copyFolder(File src, File dest)
throws IOException{
if(src.isDirectory()){
//if directory not exists, create it
if(!dest.exists()){
dest.mkdir();
System.out.println("Directory copied from "
+ src + " to " + dest);
}
//list all the directory contents
String files[] = src.list();
for (String file : files) {
//construct the src and dest file structure
File srcFile = new File(src, file);
File destFile = new File(dest, file);
//recursive copy
copyFolder(srcFile,destFile);
}
}else{
//if file, then copy it
//Use bytes stream to support all file types
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int length;
//copy the file content in bytes
while ((length = in.read(buffer)) > 0){
out.write(buffer, 0, length);
}
in.close();
out.close();
System.out.println("File copied from " + src + " to " + dest);
}
}
public static void OpenMC(int Version){
try {
Runtime rt = Runtime.getRuntime();
File mcdirectory = new File(System.getenv("APPDATA") + "\"MCMultiManager");
Process pr = rt.exec("cmd /c mklink /j .minecraft" + mcdirectory + "\"" + Version);
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line=null;
while((line=input.readLine()) != null) {
System.out.println(line);
}
int exitVal = pr.waitFor();
System.out.println("Exited with error code "+exitVal);
} catch(Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}
}
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
// End of variables declaration
}
-
Re: Help please?
I approved this for you, but it may get closed by another moderator. I only approved it since you are new and I wanted to tell you what to do in the future.
First, use a good title name. 'Help please?' may hurt more than it helps. Try making a title which asks a specific questions. If you are getting a null pointer exception try something like 'nullpointer exception when creating a gui' or something along these lines.
Next, ask clear questions, and do not dump your code here. Longer code dumps will result in less attention being paid to you. Try Short, Self Contained, Correct Example - making one of them.
If you get errors, please post the errors you receive in there entirety, in code tags.