import javax.swing.*;
   import java.awt.*;
	import java.util.*;
   import java.awt.event.*;
   import java.io.*;

    public class PartOfSpeech extends JFrame implements ActionListener
   {   
      private JButton btn1,btn2;
		private JTextArea txtAreaArticle;
      private JTextField txtField1,txtField2,txtField3;
      private JMenuBar jmb;
      private JMenu fileMenu;
      private JMenuItem out;
   
       public PartOfSpeech()
      {
         setTitle("PART OF SPEECH SYSTEM");
         Container con=getContentPane();
         con.setLayout(new BorderLayout());
      
         jmb=new JMenuBar();
         fileMenu=new JMenu("File");
         out=new JMenuItem("Exit");
         fileMenu.add(out);
         out.addActionListener(this);
         jmb.add(fileMenu);
         setJMenuBar(jmb);
      
         JPanel top=new JPanel();
         con.add(top,BorderLayout.NORTH);
			
			JTextArea txtAreaArticle = new JTextArea(15,40);
			top.add(txtAreaArticle);
			
			JPanel middle=new JPanel();
         con.add(middle,BorderLayout.CENTER);
         middle.setLayout(new GridLayout(3,6,50,50));
     
         JLabel label1=new JLabel("NUMBER OF PARAGRAPH");
         middle.add(label1);
         txtField1=new JTextField(10);
			txtField1.setEditable(true);
         middle.add(txtField1);
     
         JLabel label2=new JLabel("NUMBER OF SENTENCE");
         middle.add(label2);
         txtField2=new JTextField(10);
         txtField2.setEditable(false);
         middle.add(txtField2);
      
         JLabel label3=new JLabel("NUMBER OF WORD");
         middle.add(label3);
         txtField3=new JTextField(10);
         txtField3.setEditable(false);
         middle.add(txtField3);
            
         JPanel bottom=new JPanel();
         con.add(bottom,BorderLayout.SOUTH);
         bottom.setLayout(new FlowLayout());
      
         btn1=new JButton("Generate & Save");
         bottom.add(btn1);
         btn1.addActionListener(this);
      
         btn2=new JButton("Clear");
         bottom.add(btn2);
         btn2.addActionListener(this);
      
      
         setSize(500,600);
         setVisible(true);
      
      }
   
       public void actionPerformed(ActionEvent e)
      {
      
            	
         if(e.getSource()==btn1)
         {   


         }  
			
         if(e.getSource()==btn2)
         { 
            txtAreaArticle.setText("");
            txtField1.setText(" ");
            txtField2.setText(" ");
            txtField3.setText(" ");	 
         }
      
         if(e.getSource()==out)
         {
            System.exit(0);
         }
      }  
     
     	 
   	 public static void main (String[]args)
      {
        PartOfSpeech sys=new PartOfSpeech();
         sys.setDefaultCloseOperation(EXIT_ON_CLOSE);
      }
   }

y when i press button 2 (Clear) will error on problem textArea. Hope can help me out.

Recommended Answers

All 4 Replies

By 21 posts, you should know how to use [code] [/code] tags.

By 21 posts, you should know how to use [code] [/code] tags.

sorry... i fixed it.. u knw how to solve the problem?

Because you have declared and added that text area as a local variable in your constructor here

JTextArea txtAreaArticle = new JTextArea(15,40);

That is declaring a new JTextArea of the same name local to the constructor block. You need to drop the "JTextArea" type from that statement if you want to initialize the one you have already declared at the class level.

txtAreaArticle = new JTextArea(15,40);

Because you have declared and added that text area as a local variable in your constructor here

JTextArea txtAreaArticle = new JTextArea(15,40);

That is declaring a new JTextArea of the same name local to the constructor block. You need to drop the "JTextArea" type from that statement if you want to initialize the one you have already declared at the class level.

txtAreaArticle = new JTextArea(15,40);

thanks oh... i din realize it..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.