I've been trying to resize my jbuttons to the size of my pictures, but the jbuttons keep on occupying the whole frame.
The size of the photos are 150x267.
import javax.swing.*;
import java.awt.event.KeyListener;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.util.Timer;
import java.util.TimerTask;
public class StartGame extends JFrame implements KeyListener {
Timer timer;
JPanel startpane, oakpane, choosepane;
JButton a,b,c;
int enter = 0;
public StartGame()
{
super("Animon");
this.setBounds(100,100,1000,1000);
startpane = new JPanel();
oakpane = new JPanel();
choosepane= new JPanel();
//start
JLabel pic = new JLabel(new ImageIcon("animon2.png"));
pic.setSize(400, 500);
startpane.addKeyListener(this);
startpane.setFocusable(true);
startpane.add(pic);
add(startpane);
//oakpane
addoakpane();
//choosepane
this.addKeyListener(this);
this.setFocusable(true);
this.setVisible(true);
}
public void keyPressed(KeyEvent k){
int code;
code = k.getKeyCode();
if(k.getSource() == this)
{if(code == KeyEvent.VK_ENTER && startpane.isVisible()== true)
{
enter += 1;
startpane.setVisible(false);
remove(startpane);
repaint();
add(oakpane);
//new GameInterface(30,40);
}
else if(code == KeyEvent.VK_ESCAPE && startpane.isVisible() == false)
{
enter -=1;
startpane.setVisible(true);
add(startpane);
repaint();
}
}
}
public void keyReleased(KeyEvent k){
}
public void keyTyped(KeyEvent k){
}
public void addoakpane(){
oakpane.setLayout(new GridLayout(1,3));
//oakpane.setBounds(0, 0, 450, 267);
a = new JButton(new ImageIcon("charopt.png"));
a.setSize(150, 267);
oakpane.add(a);
b = new JButton(new ImageIcon("leaf.png"));
b.setSize(150, 267);
oakpane.add(b);
c = new JButton(new ImageIcon("squiropt.png"));
c.setSize(150, 267);
oakpane.add(c);
}
}