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

📄 showtextarea.java

📁 《A first book of java》by Gary J.Bronson 北大出版社
💻 JAVA
字号:
import javax.swing.*;
import java.awt.event.*;
import java.awt.Container;  // need this to add controls
import java.awt.*;   // needed for layout manager 
import java.text.*;  // needed for formatting
public class ShowTextArea extends JFrame
{
  private JFrame mainFrame;
  private JTextArea outArea;
 
  public ShowTextArea() // a constructor
  {
    mainFrame = new JFrame("Example of a Text Area for Output");

      // create all components
    outArea = new JTextArea(10, 28);
    
      // get the content pane 
    Container c = mainFrame.getContentPane(); 
    c.setLayout(new FlowLayout());

      // add the components to the ContentPane 
    c.add(outArea);

    mainFrame.setSize(300,250);

      // define and register window event handler
    mainFrame.addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent e) {System.exit(0);}
    });

    mainFrame.show();
  } 

  public void createTable()
  {
    int num;
    DecimalFormat df = new DecimalFormat("0000");

    outArea.setFont(new Font("Courier", Font.BOLD, 10));
    outArea.append("  NUMBER    SQUARE    CUBE\n");
    outArea.append("  ------    ------    ----\n");

    outArea.setFont(new Font("Courier", Font.PLAIN, 10));
    for (num = 1; num < 11; num++)
    {
      outArea.append("   " + df.format(num));
      outArea.append("      " + df.format(num*num));
      outArea.append("     " + df.format(num * num * num) +'\n');
    }

    return;
  }
   
  public static void main(String args[])
  {

    ShowTextArea app;  // declare an object of type ShowTextArea
    app = new ShowTextArea();  // instantiate a GUI object 

    app.createTable();
  }

}  // end of class

⌨️ 快捷键说明

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