import javax.swing.*; import java.awt.*; import java.awt.event.*; /* */ public class UpDownButton extends JApplet implements ActionListener { int x=20; JButton left, right; @Override public void init() { left = new JButton("Left"); right = new JButton("Right"); left.addActionListener(this); right.addActionListener(this); setLayout(new FlowLayout()); add(left); add(right); } @Override public void paint(Graphics g) { super.paint(g); g.drawString("HELLO WORLD!", x, 55); } public void actionPerformed(ActionEvent e) { if (e.getSource() == left) { // Leftが押された x-=10; } else if (e.getSource() == right) { // Rightが押された x+=10; } repaint(); } }