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

📄 viewer.java

📁 WAP ide 代码
💻 JAVA
字号:
package wbmp;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;/** * Viewer for WBMP files.  Constructs a dialog frame with a close button *  and a label control for displaying the image file. * Copyright (c) 2003 * @author Mark Busman * @version 1.0 * * For License and contact information see WBMPEditor.java */public class Viewer extends JDialog {  JLabel Drawinglabel = new JLabel();  JButton Closebutton = new JButton();  // Variables  static int labelSize = 1;  static Color bkg = new Color(0, 166, 8);  /** Default Constructor */  public Viewer() {  }  /** Constructor - used when running in stand-alone mode.  @param String fileName  */  public Viewer(String fName) {    try {      jbInit();      GenerateImage(fName);      pack();      this.setSize(100, 100);    }    catch(Exception e) {      e.printStackTrace();    }  }  /** Constructor - used when called from the WBMP Editor program.  @param int Width  @param int Height  @param int[][] ColorMatrix  */  public Viewer(int w, int h, int[][] matrix) {    try {      jbInit();      CreateDrawing(w, h, matrix);      pack();      this.setTitle("WBMP Preview");      this.setSize(100, 100);    }    catch(Exception e) {      e.printStackTrace();    }  }  /** Initilaization of the form's components. */  private void jbInit() throws Exception {    Closebutton.setText("Close");    Closebutton.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        Closebutton_actionPerformed(e);      }    });    this.getContentPane().setBackground(new Color(0, 166, 8));    this.getContentPane().add(Drawinglabel, BorderLayout.CENTER);    this.getContentPane().add(Closebutton, BorderLayout.SOUTH);  }  /** Used to call up the decoder when running in stand alone mode.  @param String fileName  */  private void GenerateImage(String fileName) {    Decoder decoder = new Decoder(fileName);    if (decoder.getStatus()){      String fName = fileName.substring(new File(fileName).getParent().toString().length() + 1);      this.setTitle("WBMP Viewer - " + fName);      CreateDrawing(decoder.getWidth(), decoder.getHeight(), decoder.getMatrix());    }  }  /** Main function - takes as argumets a file name.  @param String[] commandline arguments  */  public static void main(String args[]) {    Viewer v = new Viewer(args[0]);    v.show();  }  /** Performs the actual drawing on the label.  @param int Width  @param int Height  @param int[][] ColorMatrix  */  private void CreateDrawing(int w, int h, int[][] matrix) {    // clear the drawing and the previous controls    Drawinglabel.removeAll();    Drawinglabel.repaint();    Drawinglabel.setSize(w * labelSize, h * labelSize);    // define the new matrix and initialize it to background color    int ColorMatrix[][] = new int[w][h];    for (int c = 0; c < w; c++)      for (int r = 0; r < h; r++)        ColorMatrix[c][r] = matrix[c][r];    // create the new labels    JLabel l;    for (int x = 0; x < w; x++) {      for (int y = 0; y < h; y++) {        l = new JLabel();        if (ColorMatrix[x][y] == 1)          l.setBackground(bkg);        else          l.setBackground(Color.black);        l.setOpaque(true);        l.setSize(labelSize, labelSize);        l.setLocation(x * labelSize, y * labelSize);        Drawinglabel.add(l);      }    }    Drawinglabel.repaint();  }  /** Returns a label object with the drawing content   *  @param String fileName   *  @returns JLabel - a label with content  */  public JLabel getDrawing(String fName) {    GenerateImage(fName);    return Drawinglabel;  }  /** Performs the closing of the dialog window.  @param ActionEvent e  */  void Closebutton_actionPerformed(ActionEvent e) {    setVisible(false);    dispose();  }}

⌨️ 快捷键说明

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