Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: GUI Program

  1. #1
    Rikky is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Post GUI Program

    (A) Design a JFrame object with two text areas, one below the other and a button in between them. When the button is clicked, input text entered in the top text area should be converted into text without punctuation symbols (comma, semi-colon, etc) and the text should appear in the text area below the button.

    (B) Convert the application in Part (A) into a JApplet and display it inside a web page.

    This is what i have to so far, also i havent worked on B.

    Java Code:
    package assn6;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class Assn6C {
        public static void  main(String[] args){
         JFrame myframe = new JFrame("No Punc Box");
            myframe.setBounds(500,140,510,480);
            myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           
          final JTextArea ipTA, opTA;
            JButton convertBtn;
             ipTA = new JTextArea();
             opTA = new JTextArea();
             
             convertBtn = new JButton("Convert");
             myframe.setLayout(null);
             //convertBtn.addActionListener(this);
            // this.add(convertBtn);
             
             ipTA.setBounds(5,5,500,200);
             opTA.setBounds(5,250,500,200);
             convertBtn.setBounds(225,220,65,20);
            
            myframe.setVisible(true);
            myframe.add(ipTA);
            myframe.add(opTA);
            myframe.add(convertBtn);
            
            
             convertBtn.addActionListener(new ActionListener() {
     
                public void actionPerformed(ActionEvent e)
                {
                    String op;
                    op = ipTA.getText();
                    op.replaceAll("\\p{Punct}+", ""); 
                    
                    }
                
            });

  2. #2
    Rikky is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default Re: GUI Program

    im stuck here, and not sure if im going in the right direction

  3. #3
    kb9agt is offline Member
    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Default Re: GUI Program

    Classes will become objects when you make instances of them. Try to make classes for your objects. Then call them in the main class. Just keep it in the same package or even the same file. This will help you when you get to JApplet. You may then run it as an applet instead. see: The Java™ Tutorials for more info.

  4. #4
    Rikky is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default Re: GUI Program

    just finished the "easy" part..
    i added ::
    Java Code:
          public void actionPerformed(ActionEvent e)
                {
                    String op;
                   opTA.setText( ipTA.getText().replaceAll("\\p{Punct}+", "") );
                }
    I just need to make the JApplet part

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

    Default Re: GUI Program

    If this were my project, I'd gear my GUI to create a JPanel. Then if I wanted it displayed in a JFrame, I'd create a JFrame and stuff my created JPanel into its contentPane via getContentPane().add(...). Then if I wanted to display it in a JApplet, I'd create a class that extended JApplet and in the init() method add this JPanel into the applet's contentPane.

  6. #6
    gowthamgutha is offline Member
    Join Date
    Sep 2012
    Location
    Guntur, India
    Posts
    27
    Rep Power
    0

    Default Re: GUI Program

    The GUI code could be done with NetBeans or some other IDE.
    If you want to eliminate the punctuation symbols, Make an array of the punctuation symbols, write a for loop and then call replaceAll(punctuation,"") method from the String where this string is the text in the JTextArea. As the operation is not persistent on the same string, instead a new string object is created and then using the setText() method of the output JTextArea, you can set the new string.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,298
    Rep Power
    20

    Default Re: GUI Program

    Quote Originally Posted by gowthamgutha View Post
    The GUI code could be done with NetBeans or some other IDE.
    If you want to eliminate the punctuation symbols, Make an array of the punctuation symbols, write a for loop and then call replaceAll(punctuation,"") method from the String where this string is the text in the JTextArea. As the operation is not persistent on the same string, instead a new string object is created and then using the setText() method of the output JTextArea, you can set the new string.
    In what way do you think this cumbersome, inefficient approach is better than Rikky's code at #4?

    Was it really necessary to bump a thread that's nearly a month old to post this garbage?

    db
    Fubarable likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 4
    Last Post: 11-21-2012, 01:19 PM
  2. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  3. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •