-
May 26th, 2009, 04:22 PM
#1
Help! Bug?
Help! I've looked, and looked, and looked for about 3 weeks for a bug that is keeping me from moving on with the program. Okay so here's the problem. I run the program and nothing pops up. Though I figured out that all I had to do was maximize it then make it smaller again to make it show up. As you can see in the code below when I click the button called phrasemaker the text in nounbox1 should show up in the JTextArea midgui. But when I click it nothing happens! Please help!
Code:
//Phrasebot is property of shakenearth.com
//Code by Thomas Lisankie
//You may not use any of this code
//you may not distribute this program either
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.*;
import java.io.*;
import java.net.*;
public class Phrasebot implements ActionListener {
JTextField nounbox1;
JTextArea midgui;
ArrayList<String> nouns = new ArrayList();
ArrayList<String> adjectives = new ArrayList();
ArrayList<String> verbs = new ArrayList();
public static void main(String[] args){
Phrasegui gui = new Phrasegui();
gui.go();
}
public void go() {
JPanel pcenter = new JPanel();
JFrame frame = new JFrame("Phrasebot");//makes a new JFrame called "Phrasebot"
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//sets the default close operation to EXIT_ON_CLOSE
JPanel bigpanel = new JPanel();//makes a new JPanel called bigpanel
bigpanel.setLayout(new BoxLayout(bigpanel,BoxLayout.Y_AXIS));//sets bigpanel's default layout to BoxLayout
JPanel spacer = new JPanel();//makes a new JPanel called
spacer.setLayout(new BoxLayout(spacer, BoxLayout.Y_AXIS));//sets spacer's layout to BoxLayout
JLabel label = new JLabel(" ");//makes a new JLabel
spacer.add(label);//adds label to spacer
bigpanel.add(spacer);//adds spacer to bigpanel
JPanel peast = new JPanel();//makes a new panel called peast
bigpanel.add(peast);//bigpanel adds peast
peast.setLayout(new BoxLayout(peast,BoxLayout.Y_AXIS));//sets peast's layout to boxlayout
JButton morenoun = new JButton("More Nouns");//makes a new button called more noun with the text "More Nouns"
morenoun.addActionListener(new morenounListener());//morenoun adds an actionlistener which is a morenounlistener()
peast.add(morenoun);//peast adds morenoun
JButton clearnoun = new JButton("Clear Nouns");//makes a new button called clearnoun with the text "Clear Nouns"
clearnoun.addActionListener(new clearnounListener());//clearnoun adds an actionlistener which is a clearnounlistener()
peast.add(clearnoun);//peast adds clearnoun
JLabel spacer2 = new JLabel(" ");//makes a new label called spacer2
peast.add(spacer2);//peast adds spacer2
JButton moreadj = new JButton("More Adjectives");//makes a new button called moreadj with the text "More Adjectives"
moreadj.addActionListener(new moreadjListener());//moreadj adds an actionlistener which is a moreadjlistener()
peast.add(moreadj);//peast adds moreadj
JButton clearadj = new JButton("Clear Adjectives");//makes a new button called clearadj with the text "Cear Adjectives"
clearadj.addActionListener(new clearadjListener());//clearadj adds an actionlistener which is a clearadjlistener()
peast.add(clearadj);//peast adds clearadj
JLabel spacer3 = new JLabel(" ");//makes a new label called spacer3
peast.add(spacer3);//peast adds
JButton moreverb = new JButton("More Verbs");//makes a new button called moreverb with the text "More Verbs"
moreverb.addActionListener(new moreverbListener());//moreverb adds an actionlistener which is a moreverblistener()
peast.add(moreverb);//peast adds moreverb
JButton clearverb = new JButton("Clear Verbs");//makes a new button called clearverb with the text "Clear Verbs"
clearverb.addActionListener(new clearverbListener());//clearverb adds an actionlistener which is a clearverbListener()
peast.add(clearverb);//peast adds clearverb
JLabel savespacer = new JLabel(" ");//makes a new label called savespacer
peast.add(savespacer);//peast adds savespacer
JButton savewords = new JButton("Save Words");//makes a new button called save words
savewords.addActionListener(new savewordsListener());//savewords adds an actionlistener which is a savewordsListener()
peast.add(savewords);//peast adds savewords
JButton savesession = new JButton("Save Phrases");//creates a new button called savesession with the text "Save Phrases"
savesession.addActionListener(new savesessionListener());//savesession adds an actionlistener which is a savesessionListener()
peast.add(savesession);//peast adds savesession
JLabel quickspacer = new JLabel(" ");//makes a new label called quickspacer
peast.add(quickspacer);//peast adds quickspacer
JButton quick1 = new JButton("Quickie Button 1");//makes a new button called quick1 with the text "Quickie Button 1"
quick1.addActionListener(new quick1Listener());//
peast.add(quick1);
JButton quick2 = new JButton("Quickie Button 2");
quick2.addActionListener(new quick2Listener());
peast.add(quick2);
JButton quick3 = new JButton("Quickie Button 3");
quick3.addActionListener(new quick3Listener());
peast.add(quick3);
JPanel pwest = new JPanel();
pwest.setLayout(new BoxLayout(pwest,BoxLayout.Y_AXIS));
JPanel bigpanel2 = new JPanel();
bigpanel2.add(pwest);
Font midfont = new Font("Comic Sans MS", Font.BOLD, 16);
midgui = new JTextArea(10,20);
midgui.setLineWrap(true);
midgui.setFont(midfont);
JScrollPane scroll = new JScrollPane(midgui);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
pcenter.add(scroll);
JTextField nounbox1 = new JTextField("Noun ");
JTextField nounbox2 = new JTextField("Noun ");
JTextField nounbox3 = new JTextField("Noun ");
JLabel spacer4 = new JLabel(" ");
pwest.add(nounbox1);
nounbox1.addActionListener(this);
pwest.add(nounbox2);
nounbox2.addActionListener(new nounbox2Listener());
pwest.add(nounbox3);
nounbox3.addActionListener(new nounbox3listener());
pwest.add(spacer4);
JTextField adjbox1 = new JTextField("Adjective ");
JTextField adjbox2 = new JTextField("Adjective ");
JTextField adjbox3 = new JTextField("Adjective ");
JLabel spacer5 = new JLabel(" ");
pwest.add(adjbox1);
adjbox1.addActionListener(new adjbox1Listener());
pwest.add(adjbox2);
adjbox2.addActionListener(new adjbox2Listener());
pwest.add(adjbox3);
adjbox3.addActionListener(new adjbox3Listener());
pwest.add(spacer5);
JTextField verbbox1 = new JTextField("Verb ");
JTextField verbbox2 = new JTextField("Verb ");
JTextField verbbox3 = new JTextField("Verb ");
pwest.add(verbbox1);
verbbox1.addActionListener(new verbbox1Listener());
pwest.add(verbbox2);
verbbox2.addActionListener(new verbbox2Listener());
pwest.add(verbbox3);
verbbox3.addActionListener(new verbbox3Listener());
JPanel psouth = new JPanel();
JPanel bigpanel3 = new JPanel();
bigpanel3.add(psouth);
JButton phrasemaker = new JButton("Make A Phrase!");
phrasemaker.addActionListener(new phrasemakerListener());
psouth.add(phrasemaker);
frame.setSize(800,600);//sets the size of the JFrame
frame.setVisible(true);//sets the ability to see the JFrame
frame.getContentPane().add(BorderLayout.EAST, bigpanel);
frame.getContentPane().add(BorderLayout.WEST, bigpanel2);
frame.getContentPane().add(BorderLayout.SOUTH, bigpanel3);
frame.getContentPane().add(BorderLayout.CENTER, scroll);
}
public void actionPerformed(ActionEvent e) {
}
class phrasemakerListener implements ActionListener{
public void actionPerformed(ActionEvent ev) {
midgui.append(nounbox1.getText() + "\n ");
}
}
class morenounListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class clearnounListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class moreadjListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class clearadjListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class moreverbListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class clearverbListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class savewordsListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class savesessionListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class quick1Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class quick2Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class quick3Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class nounbox2Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class nounbox3listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class adjbox1Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class adjbox2Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class adjbox3Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class verbbox1Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class verbbox2Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class verbbox3Listener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
class midguiListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
}
}
}
Last edited by Shaken_Earth; May 27th, 2009 at 06:21 PM.
-
May 26th, 2009, 06:26 PM
#2
Re: Help! Bug?
When posting code, please follow the forum instructions and enclose it in CODE tags so it remains formatted and readable. I, for one, have neither the time nor the inclination to wade through a vast wodge of unformatted code.
Programs must be written for people to read, and only incidentally for machines to execute...
H. Abelson and G. Sussman
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
May 27th, 2009, 02:44 AM
#3
Re: Help! Bug?
That code does not compile, but even fixing it.... your event listeners do nothing. The only method implemented is:
Code:
public void actionPerformed(ActionEvent ev) {
midgui.append(nounbox1.getText() + "\n ");
}
And it throws a NullPointerException: nounbox is null because it never was initialized.
-
May 27th, 2009, 08:02 AM
#4
Re: Help! Bug?
//Try this code: only one line is changed
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.*;
public class Phrasebot implements ActionListener {
JTextField nounbox1;
JTextArea midgui;
ArrayList<String> nouns = new ArrayList();
ArrayList<String> adjectives = new ArrayList();
ArrayList<String> verbs = new ArrayList();
public static void main(String[] args) {
Phrasebot gui = new Phrasebot();
gui.go();
}
public void go() {
JPanel pcenter = new JPanel();
JFrame frame = new JFrame("Phrasebot");//makes a new JFrame called "Phrasebot"
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//sets the default close operation to EXIT_ON_CLOSE
JPanel bigpanel = new JPanel();//makes a new JPanel called bigpanel
bigpanel.setLayout(new BoxLayout(bigpanel, BoxLayout.Y_AXIS));//sets bigpanel's default layout to BoxLayout
JPanel spacer = new JPanel();//makes a new JPanel called
spacer.setLayout(new BoxLayout(spacer, BoxLayout.Y_AXIS));//sets spacer's layout to BoxLayout
JLabel label = new JLabel(" ");//makes a new JLabel
spacer.add(label);//adds label to spacer
bigpanel.add(spacer);//adds spacer to bigpanel
JPanel peast = new JPanel();//makes a new panel called peast
bigpanel.add(peast);//bigpanel adds peast
peast.setLayout(new BoxLayout(peast, BoxLayout.Y_AXIS));//sets peast's layout to boxlayout
JButton morenoun = new JButton("More Nouns");//makes a new button called more noun with the text "More Nouns"
morenoun.addActionListener(new morenounListener());//morenoun adds an actionlistener which is a morenounlistener()
peast.add(morenoun);//peast adds morenoun
JButton clearnoun = new JButton("Clear Nouns");//makes a new button called clearnoun with the text "Clear Nouns"
clearnoun.addActionListener(new clearnounListener());//clearnoun adds an actionlistener which is a clearnounlistener()
peast.add(clearnoun);//peast adds clearnoun
JLabel spacer2 = new JLabel(" ");//makes a new label called spacer2
peast.add(spacer2);//peast adds spacer2
JButton moreadj = new JButton("More Adjectives");//makes a new button called moreadj with the text "More Adjectives"
moreadj.addActionListener(new moreadjListener());//moreadj adds an actionlistener which is a moreadjlistener()
peast.add(moreadj);//peast adds moreadj
JButton clearadj = new JButton("Clear Adjectives");//makes a new button called clearadj with the text "Cear Adjectives"
clearadj.addActionListener(new clearadjListener());//clearadj adds an actionlistener which is a clearadjlistener()
peast.add(clearadj);//peast adds clearadj
JLabel spacer3 = new JLabel(" ");//makes a new label called spacer3
peast.add(spacer3);//peast adds
JButton moreverb = new JButton("More Verbs");//makes a new button called moreverb with the text "More Verbs"
moreverb.addActionListener(new moreverbListener());//moreverb adds an actionlistener which is a moreverblistener()
peast.add(moreverb);//peast adds moreverb
JButton clearverb = new JButton("Clear Verbs");//makes a new button called clearverb with the text "Clear Verbs"
clearverb.addActionListener(new clearverbListener());//clearverb adds an actionlistener which is a clearverbListener()
peast.add(clearverb);//peast adds clearverb
JLabel savespacer = new JLabel(" ");//makes a new label called savespacer
peast.add(savespacer);//peast adds savespacer
JButton savewords = new JButton("Save Words");//makes a new button called save words
savewords.addActionListener(new savewordsListener());//savewords adds an actionlistener which is a savewordsListener()
peast.add(savewords);//peast adds savewords
JButton savesession = new JButton("Save Phrases");//creates a new button called savesession with the text "Save Phrases"
savesession.addActionListener(new savesessionListener());//savesession adds an actionlistener which is a savesessionListener()
peast.add(savesession);//peast adds savesession
JLabel quickspacer = new JLabel(" ");//makes a new label called quickspacer
peast.add(quickspacer);//peast adds quickspacer
JButton quick1 = new JButton("Quickie Button 1");//makes a new button called quick1 with the text "Quickie Button 1"
quick1.addActionListener(new quick1Listener());//
peast.add(quick1);
JButton quick2 = new JButton("Quickie Button 2");
quick2.addActionListener(new quick2Listener());
peast.add(quick2);
JButton quick3 = new JButton("Quickie Button 3");
quick3.addActionListener(new quick3Listener());
peast.add(quick3);
JPanel pwest = new JPanel();
pwest.setLayout(new BoxLayout(pwest, BoxLayout.Y_AXIS));
JPanel bigpanel2 = new JPanel();
bigpanel2.add(pwest);
Font midfont = new Font("Comic Sans MS", Font.BOLD, 16);
midgui = new JTextArea(10, 20);
midgui.setLineWrap(true);
midgui.setFont(midfont);
JScrollPane scroll = new JScrollPane(midgui);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
pcenter.add(scroll);
// JTextField nounbox1 = new JTextField("Noun "); ----------------------------------> Incorrect
nounbox1 = new JTextField("Noun "); //--------------------------------->correct
JTextField nounbox2 = new JTextField("Noun ");
JTextField nounbox3 = new JTextField("Noun ");
JLabel spacer4 = new JLabel(" ");
pwest.add(nounbox1);
nounbox1.addActionListener(this);
pwest.add(nounbox2);
nounbox2.addActionListener(new nounbox2Listener());
pwest.add(nounbox3);
nounbox3.addActionListener(new nounbox3listener());
pwest.add(spacer4);
JTextField adjbox1 = new JTextField("Adjective ");
JTextField adjbox2 = new JTextField("Adjective ");
JTextField adjbox3 = new JTextField("Adjective ");
JLabel spacer5 = new JLabel(" ");
pwest.add(adjbox1);
adjbox1.addActionListener(new adjbox1Listener());
pwest.add(adjbox2);
adjbox2.addActionListener(new adjbox2Listener());
pwest.add(adjbox3);
adjbox3.addActionListener(new adjbox3Listener());
pwest.add(spacer5);
JTextField verbbox1 = new JTextField("Verb ");
JTextField verbbox2 = new JTextField("Verb ");
JTextField verbbox3 = new JTextField("Verb ");
pwest.add(verbbox1);
verbbox1.addActionListener(new verbbox1Listener());
pwest.add(verbbox2);
verbbox2.addActionListener(new verbbox2Listener());
pwest.add(verbbox3);
verbbox3.addActionListener(new verbbox3Listener());
JPanel psouth = new JPanel();
JPanel bigpanel3 = new JPanel();
bigpanel3.add(psouth);
JButton phrasemaker = new JButton("Make A Phrase!");
phrasemaker.addActionListener(new phrasemakerListener());
psouth.add(phrasemaker);
frame.setSize(800, 600);//sets the size of the JFrame
frame.setVisible(true);//sets the ability to see the JFrame
frame.getContentPane().add(BorderLayout.EAST, bigpanel);
frame.getContentPane().add(BorderLayout.WEST, bigpanel2);
frame.getContentPane().add(BorderLayout.SOUTH, bigpanel3);
frame.getContentPane().add(BorderLayout.CENTER, scroll);
}
public void actionPerformed(ActionEvent e) {
}
class phrasemakerListener implements ActionListener {
public void actionPerformed(ActionEvent ev) {
midgui.append(nounbox1.getText() + "\n ");
}
}
class morenounListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class clearnounListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class moreadjListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class clearadjListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class moreverbListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class clearverbListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class savewordsListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class savesessionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class quick1Listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class quick2Listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class quick3Listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class nounbox2Listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class nounbox3listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class adjbox1Listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class adjbox2Listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class adjbox3Listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class verbbox1Listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class verbbox2Listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class verbbox3Listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
class midguiListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
}
}
}
-
May 27th, 2009, 08:43 AM
#5
Re: Help! Bug?
I refer you to my previous post.
They know enough who know how to learn...
J. Adams
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
May 27th, 2009, 06:22 PM
#6
Re: Help! Bug?
Thank you so much AnandhiMohan! It worked!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|