import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.swing.*; public class sample01 extends JApplet implements ActionListener { int w, h; private static final long serialVersionUID = 1L; JTextField text_area = new JTextField(); Canvas cv; BufferedImage bi; Graphics2D offs; public void init() { w = getWidth(); h = getHeight(); bi = new BufferedImage(w, h - text_area.getHeight(),BufferedImage.TYPE_INT_ARGB); offs = (Graphics2D) bi.getGraphics(); offs.setBackground(Color.YELLOW); offs.clearRect(0,0,bi.getWidth(),bi.getHeight()); cv = new Canvas(){ private static final long serialVersionUID = 1L; public void paint(Graphics g) { g.drawImage(bi, 0, 0, null); } }; setLayout(new BorderLayout()); text_area.addActionListener(this); add(cv, BorderLayout.CENTER); add(text_area, BorderLayout.SOUTH); } public void start() { } public void actionPerformed(ActionEvent event) { System.out.println("actionPerformed:"+event); if (event.getSource() == text_area) { String tmp_str = text_area.getText(); offs.clearRect(0, 0, w, h ); offs.setColor(Color.RED); offs.drawString(tmp_str, 10, ( h / 2) ); cv.repaint(); } } }