Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Help with Java assignment - Eclipse

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Help with Java assignment - Eclipse

    Hi, I have been set an assignment for university which involves me creating a "basic" applet using Java. I have been going at this for several hours now and can't seem to make any progress. The main problem is displaying the text which I type into the textfield within the applet. Here is the basic outlines for what I have to do, any help would be greatly appreciated:

    Have a Textfield entry component which processes ActionEvents.
    In the actionPerformed() the string must be placed into a character array.
    The string must be displayed in the applet in the color blue. However to count down on plagarism, the following proviso holds: If the string typed in contains the last letter of your first name then that particular letter should always be displayed in red, and if the string contains the last letter of your surname then that letter should always be displayed in green.

    This link shows an example of what I have to create: http://www2.docm.mmu.ac.uk/STAFF/K.Yates/assig/

    Here is the code I have so far:
     import java.awt.Graphics;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
     
    public class MainClass extends JPanel  implements ActionListener {
      JTextField jtf = new JTextField(15);
      public MainClass() {
     
          add(jtf); 
          jtf.addActionListener(this); 
     
     
     
     
     
        } 
     
        // Show text when user presses ENTER. 
        public void actionPerformed(ActionEvent ae) { 
        	System.out.println(jtf.getText());
     
     
     
        } 
     
     
     
     
      public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.getContentPane().add(new MainClass());
     
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(200, 200);
        frame.setVisible(true);
     
      }
    }


    Thanks.
    Last edited by helloworld922; March 15th, 2011 at 01:23 PM.


Similar Threads

  1. Replies: 24
    Last Post: August 4th, 2014, 12:49 PM
  2. Java Assignment Help
    By welsh_rocker in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 12th, 2011, 06:02 AM
  3. my java assignment -- please help
    By java_beginner in forum Java Theory & Questions
    Replies: 6
    Last Post: May 20th, 2010, 08:32 AM
  4. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM
  5. I need extensive help with my java assignment
    By MoshMoakes in forum What's Wrong With My Code?
    Replies: 0
    Last Post: December 12th, 2009, 07:44 PM