⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swingpic.java

📁 Java学习源代码检索系统免费版
💻 JAVA
字号:
//==============================================================
// SwingPic.java - Use Swing to load and display a graphics image
//
// Java学习源代码检索系统 Ver 1.0 20031015 免费正式版
// 版权所有: 中国IT认证实验室(www.ChinaITLab.com)
// 程序制作: ChinaITLab网校教研中心
// 主页地址: www.ChinaITLab.com    中国IT认证实验室
// 论坛地址: bbs.chinaitlab.com  
// 电子邮件: Java@ChinaITLab.com
//==============================================================

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class SwingPic extends JFrame {

 // Picture file name
 protected String filename = "AS17-148-22721.jpg";
 protected ImageIcon image;

 // Constructor
 public SwingPic() {

  // Select local system look and feel
  try {
   UIManager.setLookAndFeel(
    UIManager.getCrossPlatformLookAndFeelClassName());
  } catch (Exception e) { }

  // End program when window closes
  addWindowListener(new WindowAdapter() {
   public void windowClosing(WindowEvent e) {
    System.exit(0);
   }
  });

  // Load image from file
  image = new ImageIcon(filename);
  int height = image.getIconHeight();
  int width = image.getIconWidth();

  // Create a label to hold the image as an icon
  JLabel labeledPic = new JLabel(image, JLabel.CENTER);
  labeledPic.setText(filename);

  // Create a scroller to hold the labeled image
  JScrollPane scroller = new JScrollPane(labeledPic);  
  scroller.setPreferredSize(new Dimension(height, width));

  // Add the scroller to the frame's content layer  
  Container content = getContentPane();
  content.add(scroller);
  setSize(width, height);  // Sets window's initial size
 }

 public static void main(String[] args) {
  SwingPic app = new SwingPic();
  app.setTitle("Swing Picture Demonstration");
  app.show();
 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -