OneChar - fg = new Color(red, green, blue); bg =...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//Key Event / import java.awt.*; import java.awt.event.*; import javax.swing.*; i public class OneChar extends JApplet { JTextField oneLetter = new JTextField(1); public void init() { Container c = getContentPane(); //register the listener object oneLetter.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { float red, green, blue; Color fg, bg; oneLetter.setText(" "); red = (float) Math.random(); green = (float) Math.random(); blue = (float) Math.random();
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: fg = new Color(red, green, blue); bg = Color.white; oneLetter.setForeground(fg); oneLetter.setBackground(bg); oneLetter.setCaretColor(bg); oneLetter.setFont(new Font("Courier", Font.BOLD, 200)); } }); c.setLayout(new GridLayout(1, 1)); c.setBackground(Color.white); c.add(oneLetter); JOptionPane.showMessageDialog (null, "Click on the applet, then type a key ", "Information", JOptionPane.PLAIN_MESSAGE ); } }...
View Full Document

This note was uploaded on 06/17/2011 for the course COMP 2301 taught by Professor Staff during the Spring '10 term at Kennesaw.

Ask a homework question - tutors are online