Ich möchte bei button start ein Icon hinzufügen, so wie ich es aber habe funktioniert es aber nicht.
Könnt ihr mir helfen.
Hier ist mein Code:
public static void main(String[] args)
{
JFrame sb = new JFrame();
sb.setTitle("Startbildschirm");
sb.setSize(1000, 1000);
sb.setLocationRelativeTo(null);
sb.setDefaultCloseOperation(EXIT_ON_CLOSE);
sb.setVisible(true);
JPanel panel = new JPanel();
panel.setLayout(null);
JButton ende = new JButton("Ende");
//linksPixelAbstand,ObenPixelAbstand,GrößeButton,LängeButton
ende.setBounds(10, 10, 75, 30);
ende.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
Icon icon = new ImageIcon("C:\\Users\\jhz\\Desktop\\SchiffeVersenken.png");
JButton start = new JButton(icon);
start.setBounds(10, 50, 218, 99);
panel.add(start);
panel.add(ende);
sb.add(panel);
Könnt ihr mir helfen.
Hier ist mein Code:
public static void main(String[] args)
{
JFrame sb = new JFrame();
sb.setTitle("Startbildschirm");
sb.setSize(1000, 1000);
sb.setLocationRelativeTo(null);
sb.setDefaultCloseOperation(EXIT_ON_CLOSE);
sb.setVisible(true);
JPanel panel = new JPanel();
panel.setLayout(null);
JButton ende = new JButton("Ende");
//linksPixelAbstand,ObenPixelAbstand,GrößeButton,LängeButton
ende.setBounds(10, 10, 75, 30);
ende.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
Icon icon = new ImageIcon("C:\\Users\\jhz\\Desktop\\SchiffeVersenken.png");
JButton start = new JButton(icon);
start.setBounds(10, 50, 218, 99);
panel.add(start);
panel.add(ende);
sb.add(panel);