package cn.edu.hactcm;
import java.awt.BorderLayout;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class App extends JFrame {
private JTextField textField;
public App() {
getContentPane().setLayout(new BorderLayout(0, 0));
JPanel panel = new ImagePanel();
getContentPane().add(panel);
panel.setLayout(null);
JButton btnNewButton = new JButton("New button");
btnNewButton.setBounds(108, 234, 93, 23);
panel.add(btnNewButton);
textField = new JTextField();
textField.setBounds(214, 176, 96, 19);
panel.add(textField);
textField.setColumns(10);
setSize(460, 350);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new App();
}
class ImagePanel extends JPanel {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
String path = ImagePanel.class.getClassLoader().getResource("zlp.jpg").getPath();
ImageIcon icon = new ImageIcon(path);
g.drawImage(icon.getImage(), 0, 0, null);
}
}
}