i try with .. if the user enter (-99999) in textarea ..should end the user input and go to new fframe to start execute

       public static void createAndShowGUI(){
        MainMe frame = new MainMe();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                JScrollPane jsp = new JScrollPane();
        jta = new JTextArea();
        lines = new JTextArea("01");
                lines.setBackground(Color.PINK);
        lines.setEditable(false);
 JButton button=new JButton("Click here to clear text");  
JButton button2=new JButton("Compile");  
        jta.getDocument().addDocumentListener(new DocumentListener(){
            public String getText(){
                            final int END=-9999;
                int caretPosition = jta.getDocument().getLength();
                Element root = jta.getDocument().getDefaultRootElement();
                String text = "01" + System.getProperty("line.separator");

                for(int i = 2; i < root.getElementIndex(caretPosition) +2; i++){
                    text += "0"+i + System.getProperty("line.separator");
                                        if(text=="-9999"){
                                            JOptionPane.showMessageDialog(null, text);
                                        }
                }
                return text;
                        }
                  /*     public void perform(){
                            getText();
                        }*/
            public void changedUpdate(DocumentEvent de) {
                lines.setText(getText());
            }
            public void insertUpdate(DocumentEvent de) {
                lines.setText(getText());
            }
                        public void removeUpdate(DocumentEvent de) {
                lines.setText(getText());
            }
  });


        jsp.getViewport().add(jta);
        jsp.setRowHeaderView(lines);
        jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        frame.add(jsp);
        frame.pack();
        frame.setSize(500,500);
        frame.setVisible(true);}

if(text=="-9999"){

You should use the equals() method for comparing the contents of two Strings, not the == operator.

how i can the content of textarea pass throgh switch test to get the operation

The switch statements requires a numeric value. You will have to use the Integer class's parse method to convert the contents of the textarea to a number that the switch statement can use.

text += "0"+i + System.getProperty("line.separator");
if(text=="-9999"){

Even using equals, not ==, as Norm explained, this is never going to work.
After the first statement text will contain at the very least one "0", so it can never be equal to "-9999"
What exactly was the intention behind this code?

like this is not work :

 `for(int i = 2; i < root.getElementIndex(caretPosition) +2; i++){
                            text += "0"+i + System.getProperty("line.separator");
                                                if(text.equals("-9999")){
                                                    JOptionPane.showMessageDialog(null,text);

`

and i did't get how to convert string to numberic ....
and userinput should be only numberic ..

Even using equals, not ==, as Norm explained, this is never going to work.
After the first statement text will contain at the very least one "0", so it can never be equal to "-9999"
What exactly was the intention behind this code?

i am compare only the content of textarea
and 01 ... its counter ,, (memory location "

Click Here

this is a pic for my GUI i'am comparing whats in textarea .. not in scrollbar

how to convert string to numberic .

See the Integer class. It has a parse method that will convert a String to an int.

Seems to me that you don't need the -9999 at all. Just compile the input when the user clicks "compile".
Hints:
When you get the text from the JTextArea you can split it into lines with the String class's split("\n") method.
The Integer class has a method for parsing Strings to check that they represent integers, and returning the integer value.

See the Integer class. It has a parse method that will convert a String to an int.

   public int convert (){
                            String m=getText();
                               int x=Integer.parseInt(m);
                               System.out.println(x);
                return x;
                        }

i make new method for converted .. its true now ?

What is the contents of the m variable after the getText()? Does it only contain numeric digits that you want to convert to an int value? For example: "10234"
If it has any non-numeric characters the parseInt() method will throw an exception.

That's the right general idea. (Assuming that getText() will return the text you are trying to convert).
If you check all the documentation for parseInt you will see that it throws a NumberFormatException if the String isn't a valid integer. You will need to catch that exception to deal with bad input.
(sorry Norm - I'm overlapping with you now. I'll drop out)

can i make it general .. and print message to user enter only numberic vaue ,,
i do not until now study exeptions

You can have the user enter the full program in the textarea and split it into separate lines as James suggested by using the String class's split() method. Then each line can be converted to an int by using the Integer class's parse method.
(James: I was just ready to bow out myself, but you beat me.)

i 'am using spilt
..but i want also user should enter 1111 only for digit in one line ,, if enter more its goes directly to nxt line

    public String getText(){

                int caretPosition = jta.getDocument().getLength();
                Element root = jta.getDocument().getDefaultRootElement();
                String text = "01" + System.getProperty("line.separator");

                for(int i = 2; i < root.getElementIndex(caretPosition) +2; i++){
                    text += "0"+i + System.getProperty("line.separator");
                                      text.split("\n");
                }
                             return text;
                        }

What is the purpose of the code you just posted? What is it supposed to return to its caller? How does what it returns relate to what the users types into the textarea?

What happens if you use the JTextArea's getText() method to get all of the text that the user has entered into the textarea and then use the split method to separate that into separate lines?

text.split("\n");
here how i can after 4 digit spilit .. thata what iam asking about?

Can you show the value of the String: text and what is returned by the split() method?
Write a small test program that prints out the values of those variables, compile and execute it and post it and the print out here with your questions about it.

i have confused .. i convert text into numeric and i want now to spilit 4 digit at each line ..then i send it to switch test ?
thats what i am trying to do it ?

Please post a sample of the input data you are working with. Show how you want to split it and convert it.
The String class has methods for getting sub parts of a String, depending on what is in the String.
Are you using the new compiler (1.7) that allows Strings in switch statements?

yes i'am using (1.7)
sample input is :
1007
1008
2007
3008
2109
1109
4300
0000
0000
0000
like this input :
and a define final data like first two digit means
10=read data from user in location 07 (line 7)
second line means read second num 08
20=load first num
30 = add second num
21 =store at new varible at line (location memmory 9)
43 halt stop program and show result ..
......
program should enter 4 digit in one line to read easly ..but if user makee it in one line i want to spilit each 4 digit
...

Is that sample input you posted in one String variable?
Have you tried the split method to get each "line" of that String?
String line[] = theString.split("\\n");
For example you would get an array with:
line[0] = "1007"
line[1] = "1008"
etc

       String theString = "1007\n1008\n";
       String line[] = theString.split("\\n");
       System.out.println(Arrays.toString(line));  // [1007, 1008]
jta.getDocument().addDocumentListener(new DocumentListener(){
            public String getText(){

                int caretPosition = jta.getDocument().getLength();
                Element root = jta.getDocument().getDefaultRootElement();
                String text = "01" + System.getProperty("line.separator");
                for(int i = 2; i < root.getElementIndex(caretPosition) +2; i++){
                    text += "0"+i + System.getProperty("line.separator");

                }

                             return text;
                        }

                      public int x(){
                           String theString = getText();
       String line[] = theString.split("\\n");
       System.out.println(Arrays.toString(line)); 
         String m=getText();
               int x=Integer.parseInt(m);
                return x;
                      }

how i joind between them ..
i gettext from teextarea ..how its goes to be array ?

.how its goes to be array ?

See the code I posted. theString goes to line[]

The code you have posted is very confusing. Where do you get the String from the textarea?
That String is what should be split.

System.out.println(Arrays.toString(line));
at tis line i get error
can not find symbole array

That line is for debugging. It prints out the contents of the array: line using the Arrays class's toString() method to format the array's contents. You need to import the java.util package.

package MainMe;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Element; 
import java.util.Arrays;
public class MainMe extends JFrame{
    private static JTextArea jta;
    private static JTextArea lines;
        private JPanel panel;
        JButton button=new JButton("Click here to clear text");  
JButton button2=new JButton("Compile");
 String string="";
    public MainMe(){
            super("Line Numbering Example");
     panel=new JPanel();
 panel.setLayout(new GridLayout(1,3)); 
 panel.add(button);  
 panel.add(button2);
 MainMe.Action handler =new  MainMe.Action();
 button.addActionListener(handler);  
 button2.addActionListener(handler);
add(panel,BorderLayout.SOUTH);
              JMenu fileMenu = new JMenu( "File" ); // create file menu      
//fileMenu.setMnemonic( 'F' );
JMenuItem aboutItem = new JMenuItem( "About..." );
aboutItem.setMnemonic( 'A' ); // set mnemonic to A
fileMenu.add( aboutItem ); 
aboutItem.addActionListener(
 new ActionListener() // anonymous inner class
 {
 // display message dialog when user selects About...
public void actionPerformed( ActionEvent event )
{
JOptionPane.showMessageDialog( MainMe.this,"This is an example\nof using menus",
 "About", JOptionPane.PLAIN_MESSAGE );
 } // end method actionPerformed
 } // end anonymous inner class
 );
JMenuItem exitItem = new JMenuItem( "Exit" ); // create exit item
exitItem.setMnemonic( 'x' ); // set mnemonic to x
fileMenu.add( exitItem );
exitItem.addActionListener(
 new ActionListener() // anonymous inner class
 {

  public void actionPerformed( ActionEvent event )
  {
 System.exit( 0 ); // exit application
 } // end method actionPerformed
 } // end anonymous inner class
 );
JMenuBar bar = new JMenuBar(); // create menu bar
setJMenuBar( bar ); // add menu bar to application
bar.add( fileMenu );
}  
 private class Action implements ActionListener{
public void actionPerformed(ActionEvent event)  
{  
 if(event.getSource()==button)  
 {  
   jta.setText("");  
 }  
 if (event.getSource()==button2){
      string=String.format(jta.getText());
      JOptionPane.showMessageDialog(null,string);   
 }
}
 }
       public static void createAndShowGUI(){
        MainMe frame = new MainMe();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                JScrollPane jsp = new JScrollPane();
        jta = new JTextArea();
        lines = new JTextArea("01");
                lines.setBackground(Color.PINK);
        lines.setEditable(false);
 JButton button=new JButton("Click here to clear text");  
JButton button2=new JButton("Compile");  
        jta.getDocument().addDocumentListener(new DocumentListener(){
            public String getText(){

                int caretPosition = jta.getDocument().getLength();
                Element root = jta.getDocument().getDefaultRootElement();
                String text = "01" + System.getProperty("line.separator");
                for(int i = 2; i < root.getElementIndex(caretPosition) +2; i++){
                    text += "0"+i + System.getProperty("line.separator");

                }

                             return text;
                        }
                   public int x(){
                           String theString = getText();
       String line[] = theString.split("\\n");
       System.out.println(Arrays.toString(line)); 
         String m=getText();
               int x=Integer.parseInt(m);
                return x;
                      }
                  /*     public void perform(){
                            getText();
                        }*/
            public void changedUpdate(DocumentEvent de) {
                lines.setText(getText());
            }
            public void insertUpdate(DocumentEvent de) {
                lines.setText(getText());
            }
                        public void removeUpdate(DocumentEvent de) {
                lines.setText(getText());
            }
  });
        jsp.getViewport().add(jta);
        jsp.setRowHeaderView(lines);
        jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        frame.add(jsp);
        frame.pack();
        frame.setSize(500,500);
        frame.setVisible(true);}
     public static void main(String[] args){

                createAndShowGUI();


    }}

it is not work as i want ,,, i should submitt tomorow . and i have exam until now i don't study ..
.. i can't do simple simulator :

it is not work as i want

Can you explain what the problem is with what the code does?

I can't implement compiler that take program in assembly language and executed with this gui

When I execute the code a JOptionPane box on line 71 shows the contents of the JTextArea. Where does that String need to go to be "executed"? The last code posted here does nothing with the String of assembly language instructions.

yes .. i make it to test the button .. i will changed to be executed user program when user press compile ...
...
yes i know its nothing .. i don't know how i can start with it .. i was post before code .that define instructions as final data ..:/

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.