0082おれさま ◆6CTEZS59O00a
2018/10/03(水) 14:18:29.06最も基礎レベルのコードがこれ
public class Main extends JFrame {
Main() {
setSize(200, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pnl = new JPanel();
JButton btn = new JButton("押して・・・・");
pnl.add(btn);
Container contentPane = getContentPane();
contentPane.add(pnl, BorderLayout.CNETER);
MyListener ml = new MyListener();//@
btn.addActionListener(ml);//A
}
public static void main(String[] args) {
Main ma = new Main();
ma.setVisible(true);
}
}
class MyListener implements ActionListener {//B
public void actionPerformed(ActionEvent e) {
System.out.println("あ〜ん");
}
}