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.