import javax.swing.*; import java.awt.*; import java.awt.event.*; /* */ public class UpDownButton2 extends JApplet { int x = 20; public class LeftListener implements ActionListener { public void actionPerformed(ActionEvent e) { x -= 10; repaint(); } } public class RightListener implements ActionListener { public void actionPerformed(ActionEvent e) { x += 10; repaint(); } } @Override public void init() { JButton lBtn = new JButton("Left"); JButton rBtn = new JButton("Right"); lBtn.addActionListener(new LeftListener()); rBtn.addActionListener(new RightListener()); setLayout(new FlowLayout()); add(lBtn); add(rBtn); } @Override public void paint(Graphics g) { super.paint(g); g.drawString("HELLO WORLD!", x, 55); } public static void main(String[] args) { JFrame frame = new JFrame(""); JApplet applet = new UpDownButton2(); applet.setPreferredSize(new Dimension(200, 70)); frame.add(applet); frame.pack(); frame.setVisible(true); applet.init(); applet.start(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }