Sidewinder | Please use [php], [code] and [highlight="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: The Forum Rules.
Alright, I'm very puzzled. I get an error on compile and I can't fix it. Any ideas?
[highlight="Java"]/*
* GUI.java
*
* Created on September 29, 2007, 9:37 PM
*/
package nasg;
import java.io.*;
import java.lang.reflect.Method;
import java.util.Arrays;
import javax.swing.JOptionPane;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author Victor
*/
public class GUI{
/** Creates new form GUI */
public GUI() {
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.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jComboBox1 = new javax.swing.JComboBox();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
setTitle("Neo's Admin Script Generator 0.5");
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
setLocationByPlatform(true);
setResizable(false);
addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
formKeyPressed(evt);
}
});
getAccessibleContext().setAccessibleName("nasg");
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "r", "m", "m4m", "m4a1auto", "ma", "ar", "g", "at4", "s", "s82", "s24", "spr", "m9", "b", "sf", "ak", "ak74su", "gp", "rpg", "rpk", "svd", "mos", "v", "d", "pso", "bdm" }));
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jComboBox1ActionPerformed(evt);
}
});
jTextArea1.setColumns(20);
jTextArea1.setLineWrap(true);
jTextArea1.setRows(5);
jTextArea1.setText("Enter Admin Message");
jTextArea1.setToolTipText("You can enter your administrator's message here");
jTextArea1.setWrapStyleWord(true);
jScrollPane1.setViewportView(jTextArea1);
jLabel1.setText("Weapon Class");
jButton1.setText("Compile!");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGap(73, 73, 73)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILI NG, layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jButton1)))
.addGroup(layout.createSequentialGroup()
.addContainerGap(34, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(23, 23, 23)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.BASELINE)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(23, 23, 23)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 31, Short.MAX_VALUE)
.addComponent(jButton1)
.addContainerGap())
);
pack();
}// </editor-fold>
private void formKeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
}
private void jComboBox1ActionPerformed(java.awt.event.ActionEve nt evt) {
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
JComboBox jcmbType = (JComboBox)e.getSource();
String cmbType = (String)jcmbType.getSelectedItem();
jComboBox1ActionPerformed(evt);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
FileOutputStream fout;
try {
fout = new FileOutputStream("nasg.txt");
for(int number = 1; number <= 50; number++) {
new PrintStream(fout).println("admin forceclass " + cmdType);
}
new PrintStream(fout).println("admin message ");
new PrintStream(fout).println("admin say ");
fout.close();
} catch (IOException e) {
System.err.println("Unable to write to file");
System.exit(-1);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration
[/highlight]
And my error:
Sidewinder | Please use [php], [code] and [highlight="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: The Forum Rules.init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Victor\My Documents\Java\NASG\build\classes
C:\Documents and Settings\Victor\My Documents\Java\NASG\src\nasg\GUI.java:155: reached end of file while parsing
private javax.swing.JTextArea jTextArea1;
1 error
BUILD FAILED (total time: 1 second)
Last edited by John; 10-02-2007 at 09:08 PM.
It looks like your missing two closing braces and one closing parenthesis in this method.
[HIGHLIGHT="Java"] private void jComboBox1ActionPerformed(java.awt.event.ActionEve nt evt) {
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
JComboBox jcmbType = (JComboBox)e.getSource();
String cmbType = (String)jcmbType.getSelectedItem();
jComboBox1ActionPerformed(evt);
} [/HIGHLIGHT]
Should be:
[HIGHLIGHT="Java"]private void jComboBox1ActionPerformed(java.awt.event.ActionEve nt evt) {
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
JComboBox jcmbType = (JComboBox)e.getSource();
String cmbType = (String)jcmbType.getSelectedItem();
jComboBox1ActionPerformed(evt);
}
});
} [/HIGHLIGHT]
I think.
Last edited by John; 10-02-2007 at 09:24 PM.
Still not working, I get 13 errors now.
Am I missing a declaration maybe?Code:init: deps-jar: Compiling 1 source file to C:\Documents and Settings\Victor\My Documents\Java\NASG\build\classes C:\Documents and Settings\Victor\My Documents\Java\NASG\src\nasg\GUI.java:41: cannot find symbol symbol : method setDefaultCloseOperation(int) location: class nasg.GUI setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); C:\Documents and Settings\Victor\My Documents\Java\NASG\src\nasg\GUI.java:42: cannot find symbol symbol : method setTitle(java.lang.String) location: class nasg.GUI setTitle("NASG 0.5 Alpha"); C:\Documents and Settings\Victor\My Documents\Java\NASG\src\nasg\GUI.java:43: cannot find symbol symbol : method setCursor(java.awt.Cursor) location: class nasg.GUI setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); C:\Documents and Settings\Victor\My Documents\Java\NASG\src\nasg\GUI.java:44: cannot find symbol symbol : method addFocusListener(<anonymous java.awt.event.FocusAdapter>) location: class nasg.GUI addFocusListener(new java.awt.event.FocusAdapter() { C:\Documents and Settings\Victor\My Documents\Java\NASG\src\nasg\GUI.java:49: cannot find symbol symbol : method addKeyListener(<anonymous java.awt.event.KeyAdapter>) location: class nasg.GUI addKeyListener(new java.awt.event.KeyAdapter() { C:\Documents and Settings\Victor\My Documents\Java\NASG\src\nasg\GUI.java:55: cannot find symbol symbol : method getAccessibleContext() location: class nasg.GUI getAccessibleContext().setAccessibleName("nasg"); C:\Documents and Settings\Victor\My Documents\Java\NASG\src\nasg\GUI.java:94: cannot find symbol symbol : method getContentPane() location: class nasg.GUI javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); C:\Documents and Settings\Victor\My Documents\Java\NASG\src\nasg\GUI.java:95: cannot find symbol symbol : method getContentPane() location: class nasg.GUI getContentPane().setLayout(layout); C:\Documents and Settings\Victor\My Documents\Java\NASG\src\nasg\GUI.java:134: cannot find symbol symbol : method pack() location: class nasg.GUI pack(); C:\Documents and Settings\Victor\My Documents\Java\NASG\src\nasg\GUI.java:156: cannot find symbol symbol: class JComboBox JComboBox jcmbType = (JComboBox)e.getSource(); C:\Documents and Settings\Victor\My Documents\Java\NASG\src\nasg\GUI.java:156: cannot find symbol symbol: class JComboBox JComboBox jcmbType = (JComboBox)e.getSource(); C:\Documents and Settings\Victor\My Documents\Java\NASG\src\nasg\GUI.java:156: cannot find symbol symbol: variable e JComboBox jcmbType = (JComboBox)e.getSource(); C:\Documents and Settings\Victor\My Documents\Java\NASG\src\nasg\GUI.java:187: cannot find symbol symbol : method setVisible(boolean) location: class nasg.GUI new GUI().setVisible(true); 13 errors BUILD FAILED (total time: 0 seconds)
Do you use an IDE? You should really try out Eclipse.
I just put your code into my Eclipse and it has more than those 13 errors.
First off, in your initComponents() method there are several methods that aren't called on an object. Meaning, you never created a JFrame/Applet so you cant call the setTitle, setCursor, setLocationByPlatform methods on nothing.
Second, you declare your "global" variables [jButton1, jComboBox1, ect...] at the end of the class - they should be declared before they are used.
Third, it doesn't look like your class is actually closed.
Fourth, there are some type mismatches.
Like I said, just pop your code into eclipse and your screen will light up with red errors.
I never used NetBeans. I tend to try and stay away from program's that "do it" for you, that way when you are presented with a problem like this, you aren't clueless. I wasn't going to say anything about the code because I don't to criticize other developers, especially if they are new, but a lot of the code just seems backwards.
I've taken three college classes on Java and I have never seen variable deceleration at the end of the class. I don't know if thats a beans thing, but I makes no sense.
I've written several tutorials on building GUI's in the tutorials section, if you have any questions, feel free to post there.
It must be a NetBeans thing, b/c the only code I actually put in myself was the action events (not sure if right terminology). Everything else I just went to design. Even the class, NetBeans setup that up when I made the project. Alot of the script, NetBeans doesn't even let me edit, especially in the guts of the GUI, I can't edit it. Which is why I was so puzzled in the first place, NetBeans was supposed to take care of it. I'm going to try out Eclipse, looks pretty solid but I've haven't downloaded it yet. Thanks for all your help sidewinder!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks