📄 scrollingimage.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ScrollingImage
extends JFrame
implements ActionListener {
private JLabel imageLabel = new JLabel();
private JButton quit = new JButton("Quit");
private String fileName = "scenery.jpg";
public ScrollingImage() {
super("Scrolling Image");
ImageIcon icon = new ImageIcon(fileName);
imageLabel.setIcon(icon);
JScrollPane scrollingLabel = new JScrollPane(imageLabel);
scrollingLabel.setPreferredSize(new Dimension(300, 150));
JPanel info = new JPanel(new GridLayout(3, 1));
info.add(new JLabel("Image Name: " + fileName));
info.add(new JLabel("Image Width: " + icon.getIconWidth()));
info.add(new JLabel("Image Height: " + icon.getIconHeight()));
JTabbedPane tabs = new JTabbedPane();
tabs.addTab("Image", scrollingLabel);
tabs.addTab("Info", info);
JPanel buttons = new JPanel(new FlowLayout());
buttons.add(quit);
getContentPane().add("Center", tabs);
getContentPane().add("South", buttons);
quit.addActionListener(this);
validate();
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
System.exit(0);
}
public static void main(String args[]) {
ScrollingImage si = new ScrollingImage();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -