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

📄 graphicalscreenresizedialog.java

📁 WAP ide 代码
💻 JAVA
字号:
package wapide;import javax.swing.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.event.*;import javax.swing.text.*;import java.util.*;/** * Copyright:    Copyright (c) 2003 * @author Mark Busman * @version 1.0 * * For License and contact information see WAPIDE.java */public class GraphicalScreenResizeDialog extends JDialog {  private BorderLayout borderLayout1 = new BorderLayout();  private JPanel jPanel2 = new JPanel();  private FlowLayout flowLayout1 = new FlowLayout();  private JButton CancelButton = new JButton();  private JButton OkButton = new JButton();  private JPanel jPanel1 = new JPanel();  private GridLayout gridLayout1 = new GridLayout();  private JPanel jPanel3 = new JPanel();  private JPanel jPanel4 = new JPanel();  private BorderLayout borderLayout2 = new BorderLayout();  private BorderLayout borderLayout3 = new BorderLayout();  private JPanel jPanel6 = new JPanel();  private JTextField WordsTextPane = new JTextField();  private JTextField LinesTextPane = new JTextField();  private JPanel jPanel5 = new JPanel();  private GridLayout gridLayout2 = new GridLayout();  private GridLayout gridLayout3 = new GridLayout();  private ImageIcon image1;  private ImageIcon image2;  private JLabel jLabel1 = new JLabel();  private JLabel jLabel2 = new JLabel();  private JScrollBar WordsScrollbar = new JScrollBar();  private JScrollBar LinesScrollbar = new JScrollBar();  // User Variables  /**   * Stores the width of the screen.  Words is used because it represents how   * many words can fit on a line.  Value stored is in pixels at the moment   * but eventually it might go to points so as to work better with   * font sizes.   */  private int words = 0;  /**   * Stores the height of the screen.  lines is used because it represents how   * many lines of text can fit on the screen.  Value stored is in pixels at   * the moment but eventually it might go to points so as to work better with   * font sizes.   */  private int lines = 0;  /**   * Used to determine how the dialog was closed, false if Ok pressed, true if   * Cancel button pressed.   */  private boolean cancelled = false;  /**   * Constructs a ScreenResizeDialog with default values set.   * @param int word - width of the screen in pixels.   * @param int line - height of the screen in pixels.   */  public GraphicalScreenResizeDialog(int word, int line) {    try {      words = word;      lines = line;      jbInit();      pack();      setResizable(false);      WordsTextPane.setText(new Integer(words).toString());      LinesTextPane.setText(new Integer(lines).toString());      WordsScrollbar.setValue(words);      LinesScrollbar.setValue(lines);    }    catch(Exception e) {      e.printStackTrace();    }  }  /**   * Initializes the dialog and its controls.   */  private void jbInit() throws Exception {    this.setModal(true);    this.setTitle("Resize Text Area");    this.getContentPane().setLayout(borderLayout1);    jPanel2.setLayout(flowLayout1);    flowLayout1.setAlignment(FlowLayout.RIGHT);    CancelButton.setText("Cancel");    CancelButton.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        CancelButton_actionPerformed(e);      }    });    OkButton.setPreferredSize(new Dimension(81, 23));    OkButton.setText("Ok");    OkButton.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        OkButton_actionPerformed(e);      }    });    jPanel1.setLayout(gridLayout1);    gridLayout1.setRows(2);    gridLayout1.setColumns(1);    gridLayout1.setVgap(17);    jPanel3.setLayout(borderLayout2);    jPanel4.setLayout(borderLayout3);    WordsTextPane.setPreferredSize(new Dimension(74, 13));    WordsTextPane.setText("90");    WordsTextPane.addKeyListener(new java.awt.event.KeyAdapter() {      public void keyTyped(KeyEvent e) {        WordsTextPane_keyTyped(e);      }    });    WordsTextPane.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        WordsTextPane_actionPerformed(e);      }    });    LinesTextPane.setPreferredSize(new Dimension(74, 13));    LinesTextPane.setToolTipText("");    LinesTextPane.setText("64");    LinesTextPane.addKeyListener(new java.awt.event.KeyAdapter() {      public void keyTyped(KeyEvent e) {        LinesTextPane_keyTyped(e);      }    });    LinesTextPane.addActionListener(new java.awt.event.ActionListener() {      public void actionPerformed(ActionEvent e) {        LinesTextPane_actionPerformed(e);      }    });    jPanel6.setLayout(gridLayout2);    jPanel5.setLayout(gridLayout3);    gridLayout2.setRows(2);    gridLayout2.setColumns(1);    gridLayout3.setRows(2);    gridLayout3.setColumns(1);    jLabel1.setText("Width of the screen (in pixels)");    jLabel2.setText("Height of the screen (in pixels)");    WordsScrollbar.setMaximum(1600);    WordsScrollbar.setValue(90);    WordsScrollbar.setPreferredSize(new Dimension(17, 21));    WordsScrollbar.addAdjustmentListener(new java.awt.event.AdjustmentListener() {      public void adjustmentValueChanged(AdjustmentEvent e) {        WordsScrollbar_adjustmentValueChanged(e);      }    });    LinesScrollbar.setMaximum(1600);    LinesScrollbar.setValue(64);    LinesScrollbar.setPreferredSize(new Dimension(17, 21));    LinesScrollbar.addAdjustmentListener(new java.awt.event.AdjustmentListener() {      public void adjustmentValueChanged(AdjustmentEvent e) {        LinesScrollbar_adjustmentValueChanged(e);      }    });    this.getContentPane().add(jPanel2, BorderLayout.SOUTH);    jPanel2.add(OkButton, null);    jPanel2.add(CancelButton, null);    this.getContentPane().add(jPanel1, BorderLayout.CENTER);    jPanel1.add(jPanel3, null);    jPanel3.add(jPanel6, BorderLayout.SOUTH);    jPanel3.add(WordsTextPane, BorderLayout.CENTER);    jPanel3.add(jLabel1, BorderLayout.NORTH);    jPanel3.add(WordsScrollbar, BorderLayout.EAST);    jPanel1.add(jPanel4, null);    jPanel4.add(LinesTextPane, BorderLayout.CENTER);    jPanel4.add(jPanel5, BorderLayout.SOUTH);    jPanel4.add(jLabel2, BorderLayout.NORTH);    jPanel4.add(LinesScrollbar, BorderLayout.EAST);    image1 = new ImageIcon(wapide.IDEFrame.class.getResource("uparrow.gif"));    image2 = new ImageIcon(wapide.IDEFrame.class.getResource("downarrow.gif"));  }  /**Overridden so we can exit when window is closed*/  protected void processWindowEvent(WindowEvent e) {    if (e.getID() == WindowEvent.WINDOW_CLOSING) {      CancelButton.doClick();    }    super.processWindowEvent(e);  }  /**   * Handles the Ok Button, if pressed sets variables and hides the dialog.  Sets   * cancelled to false.   */  private void OkButton_actionPerformed(ActionEvent e) {    try {      words = Integer.parseInt(WordsTextPane.getText());      lines = Integer.parseInt(LinesTextPane.getText());      cancelled = false;      setVisible(false);    }    catch (NumberFormatException err) {      JOptionPane.showMessageDialog(this, "Only numerical values are accepted", "Warning", JOptionPane.WARNING_MESSAGE);    }  }  /**   * Handles the Cancel Button, if pressed records cancel button pressed and hides   * dialog.   */  private void CancelButton_actionPerformed(ActionEvent e) {    cancelled = true;    setVisible(false);  }  /**   * Returns the way the dialog was exited, true means cancel button or close   * button pressed, false means OK Button pressed.   */  public boolean getStatus() {    return cancelled;  }  /**   * Retrieves the values for words(width) and lines(height).   * @return Vector values - the values stored as follows:<br>   * words<br>   * lines   */  public Vector getValues() {    Vector v = new Vector();    v.add(new Integer(words));    v.add(new Integer(lines));    return v;  }  /**   * If the words(width) value scrollbar is used, adjusts the   * value accordingly.   */  private void WordsScrollbar_adjustmentValueChanged(AdjustmentEvent e) {    Integer i = new Integer(WordsScrollbar.getValue());    WordsTextPane.setText(i.toString());  }  /**   * If the lines(height) value scrollbar is used, adjusts the value   * accordingly.   */  private void LinesScrollbar_adjustmentValueChanged(AdjustmentEvent e) {    Integer i = new Integer(LinesScrollbar.getValue());    LinesTextPane.setText(i.toString());  }  /**   * Sets the appropriate scrollbar to reflect the value entered.   */  private void WordsTextPane_actionPerformed(ActionEvent e) {    try {      WordsScrollbar.setValue(Integer.parseInt(WordsTextPane.getText()));    }    catch (NumberFormatException err) {}  }  /**   * Sets the appropriate scrollbar to reflect the value entered.   */  private void LinesTextPane_keyTyped(KeyEvent e) {    try {      LinesScrollbar.setValue(Integer.parseInt(LinesTextPane.getText()));    }    catch (NumberFormatException err) {}  }  /**   * Sets the appropriate scrollbar to reflect the value entered.   */  private void WordsTextPane_keyTyped(KeyEvent e) {    try {      WordsScrollbar.setValue(Integer.parseInt(WordsTextPane.getText()));    }    catch (NumberFormatException err) {}  }  /**   * Sets the appropriate scrollbar to reflect the value entered.   */  private void LinesTextPane_actionPerformed(ActionEvent e) {    try {      LinesScrollbar.setValue(Integer.parseInt(LinesTextPane.getText()));    }    catch (NumberFormatException err) {}  }}

⌨️ 快捷键说明

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