Wie fügt man Bilder in ein GUI ein? Ich schicke einfach mal meinen bisherigen GUI Code mit:
Java:
package javaPersonData;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JSeparator;
import java.awt.Button;
import javax.swing.ImageIcon;
import javax.swing.JButton;
public class LoginGUI {
private JFrame frame;
private JTextField textField;
private JTextField textField_1;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
LoginGUI window = new LoginGUI();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public LoginGUI() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame("Log In");
frame.setBounds(100, 100, 590, 433);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setResizable(false);
ImageIcon login_picture = new ImageIcon("/Users/root/eclipse-workspace/UniDatenbank/src/images/bild1.jpeg");
JPanel panel = new JPanel();
panel.setBackground(Color.DARK_GRAY);
panel.setBounds(0, 0, 293, 411);
frame.getContentPane().add(panel);
JLabel lblUsername = new JLabel("Username");
lblUsername.setBounds(336, 91, 69, 24);
frame.getContentPane().add(lblUsername);
JLabel lblPassword = new JLabel("Password");
lblPassword.setBounds(336, 161, 61, 16);
frame.getContentPane().add(lblPassword);
textField = new JTextField();
textField.setBounds(336, 118, 185, 31);
frame.getContentPane().add(textField);
textField.setColumns(10);
textField_1 = new JTextField();
textField_1.setBounds(336, 182, 185, 31);
frame.getContentPane().add(textField_1);
textField_1.setColumns(10);
JSeparator separator = new JSeparator();
separator.setBackground(Color.GRAY);
separator.setBounds(336, 361, 209, 16);
frame.getContentPane().add(separator);
JLabel lblDontHaveA = new JLabel("Don't have a Account?");
lblDontHaveA.setBounds(336, 373, 144, 16);
frame.getContentPane().add(lblDontHaveA);
JButton btnNewButton = new JButton("Register");
btnNewButton.setBounds(475, 370, 77, 24);
frame.getContentPane().add(btnNewButton);
JButton btnLogIn = new JButton("Log In");
btnLogIn.setBounds(336, 249, 185, 41);
frame.getContentPane().add(btnLogIn);
JLabel lblUniverityLogin = new JLabel("University Login");
lblUniverityLogin.setBounds(368, 19, 144, 16);
frame.getContentPane().add(lblUniverityLogin);
}
}