Results 1 to 7 of 7
Like Tree4Likes
  • 3 Post By Fubarable
  • 1 Post By Norm

Thread: First GUI application.

  1. #1
    Nazneen Ali is offline Senior Member
    Join Date
    Jul 2011
    Posts
    112
    Rep Power
    0

    Unhappy First GUI application.

    I have to develop a GUI application similar to the one attached in the name "sample GUI". I don't know much abc of developing a GUI and I can't read any tutorials for the time being because I am really short of time.
    It uses two classes I have, named DNA and Protein.
    I have attached a file named "mine gui" which is the work I have done so far.
    Now, I have got the following code for reference. But i don't know where to write that code.

    Java Code:
    [B]//Reference 
    
    
    //Change Value in ComboBox[/B]
    
    jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { 
    "Item 1", "Item 2", "Item 3", "Item 4" }));
    
    [B]//Change Selection Mode of  RadioButton[/B]
    
    jRadioButton1.setSelected(true);
    
    jRadioButtonDNA.isSelected();
    
    [B]//Get and Set Value from TextArea[/B]
    
    jTextArea1.getText();
    
    jTextArea1.setText(“Your text”);
    
    [B]//Compare ComboBox Selected Text[/B]
    
    if( jComboBox1.getSelectedItem().toString().equals("Name"))
    {
          //Code here
    }
    [B]//Set Text to Label[/B]
    
    jLabel1.setText(“Your Text”);
    
    [B]//JFileChoose Code[/B]
    
    JFileChooser fc = new JFileChooser();
    int returnVal = fc.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION)
          System.out.println(fc.getSelectedFile() ); ///its give you file path which is selected
    1. First of all, the user clicks on the Browse button. The code against it should choose the path the user selects. What code does that?

    2. Then the code against the text field named TextFieldFilePath should paste the selested path in the text field. What code does that?

    3. Then the user clicks on the Read button. This should invoke the method in the DNA class which reads text from the file. The file contains the name of the sequence and the sequence itself, separated by the tokenizer ">". But in the GUI, the name of the sequence has to be displayed in a text field and the sequence has to displayed in a text area, separately. How to achieve that?
    The method which reads from the file has void return type. Even if I change it to string, what should it return- name of the sequence( which is to be displayed in the text field against the label saying "Sequence Name" ) or the sequence itself( to be displayed in the text area below the label saying "Sequence"). The method to read the file prints the name and the sequence separately, in console mode.
    This is the code of the method:
    Java Code:
    void readFromFile(String path){
           String stringFromFile= new String();
    
            try
           {
               FileReader fro = new FileReader( path );
               BufferedReader bro = new BufferedReader( fro );
              String strline= bro.readLine( );
    
              stringFromFile= "";
              while( strline!= null )
              {  stringFromFile+= strline;
              strline= bro.readLine( );
              }
    
              bro.close( );}
           catch( FileNotFoundException filenotfoundexxption)
           {
               System.out.println( "FastaDNA.txt, does not exist" );
           }
           catch( IOException ioexception)
           {
               ioexception.printStackTrace( );
           }
    
    
           System.out.println("To test if the file, FastaDNA.text located in G drive, has been read:\nSEQUENCE NAME:" + stringFromFile.substring(0, stringFromFile.indexOf(">")));
           System.out.println("SEQUENCE:"+ stringFromFile.substring(stringFromFile.indexOf(">")+1,stringFromFile.length()));
    
    
        }
    4. Then there should be a code against the jTextFieldSequenceName which should display the name of the sequence. What code does that?

    5.There should be a code against jTextAreaInput which should display the sequence in the text area.

    6. Then the user selects one of the jRadioButtons. Shall I copy the reference code and paste it there?

    7. Then the user selects from the jComboBox. Shall I copy the refernce code and paste it there?
    The user's selection has to be bases on their selection from the two radio buttons. i.e. The options in the combobox have to be different for each of the two radiobuttons.

    8. Then on the basis of user's selection from the jComboBox, relevant method has to be invoked from the class and then the output should be displayed in the jTextAreaOutput. How to do that?

    9.What code against the jTextAreaOutput displays the output in it?
    Attached Thumbnails Attached Thumbnails First GUI application.-sample-gui.jpg   First GUI application.-mine-gui.jpg  
    Last edited by Nazneen Ali; 07-24-2011 at 06:57 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,319
    Rep Power
    25

    Default

    I can't read any tutorials for the time being
    There are a lot of good examples in the Tutorials.

    I'd suggest you start with a simple GUI in a JFrame with some buttons and text areas to see how to create the GUI.
    Add some listeners to the buttons and have them put text into the text areas.
    When you understand how that works, then you can think about the design for the program you want to write.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Nazneen Ali View Post
    I have to develop a GUI application similar to the one attached in the name "sample GUI". I don't know much abc of developing a GUI and I can't read any tutorials for the time being because I am really short of time.
    You really should have a look at the Swing tutorials as all of your questions are explained by professionals in a way far better than we could possibly do, and the knowledge gained will also help you ask more pointed questions here. And sorry to mention but while you're at it, consider checking out some tutorials on time management.

    Best of luck on this project and your Java education!
    Jodokus, Dark and Nazneen Ali like this.

  4. #4
    Nazneen Ali is offline Senior Member
    Join Date
    Jul 2011
    Posts
    112
    Rep Power
    0

    Default

    There are a lot of good examples in the Tutorials.
    You really should have a look at the Swing tutorials as all of your questions are explained by professionals in a way far better than we could possibly do, and the knowledge gained will also help you ask more pointed questions here.
    I definitely will read the tutorials for my project, after a week. Right now, the problem is that I have to submit this class assignment tomorrow morning and I have only a few hours at my expense.

    What should I do now? Please suggest me something.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,319
    Rep Power
    25

    Default

    What should I do now?
    There is not much you can do until you get the needed knowledge.

    You could always hire a programmer to write your code for you.

  6. #6
    Nazneen Ali is offline Senior Member
    Join Date
    Jul 2011
    Posts
    112
    Rep Power
    0

    Default

    [QUOTEYou could always hire a programmer to write your code for you.
    ][/QUOTE]
    Hiring a programmer for our assignments? I have never heard about it. And I want to do it myself.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,319
    Rep Power
    25

    Default

    Another way to put get some code would be to Search on the forum for samples and then try to modify them.

    I hope the other helpers here don't see this as they be on me for creating more headaches for them.
    Nazneen Ali likes this.

Similar Threads

  1. Replies: 3
    Last Post: 12-04-2009, 12:10 PM
  2. Replies: 1
    Last Post: 08-05-2009, 02:43 AM
  3. Replies: 0
    Last Post: 04-22-2009, 01:30 PM
  4. Replies: 0
    Last Post: 02-16-2008, 09:31 PM
  5. Replies: 0
    Last Post: 02-16-2008, 09:29 PM

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
  •