package ru.nz.tamagotchi.main; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JPanel; public class MyPanel extends JPanel { JButton btnEat; JButton btnSleep; JButton btnNewButton; KeyListener listen = new KeyListener(); public MyPanel() { setLayout(null); btnEat = new JButton("Eat"); btnEat.setBounds(350, 11, 89, 30); btnEat.addActionListener(listen); add(btnEat); btnSleep = new JButton("Sleep"); btnSleep.setBounds(350, 52, 89, 30); btnSleep.addActionListener(listen); add(btnSleep); btnNewButton = new JButton("Status"); btnNewButton.setBounds(350, 93, 89, 30); btnNewButton.addActionListener(listen); add(btnNewButton); } Image img = new ImageIcon("pics/back.jpg").getImage(); public void paint(Graphics g) { g = (Graphics2D) g; g.drawImage(img, 0, 70, null); } class KeyListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (e.getSource() == (btnEat)) { Main.pet.feed(); } if (e.getSource() == (btnSleep)) { Main.pet.sleep(); } if (e.getSource() == (btnNewButton)) { Main.pet.status(); } } } }