程序多窗口功能研究,代码来源于一位大佬的Java教材。
Gives a program that creates a main window with a text area in the scroll pane
and a button named Show Histogram. When the user clicks the button, a new window appears
that displays a histogram to show the occurrences of the letters in the text area. Figure 17.15
contains a sample run of the program.
编写一个程序,创建一个主窗口,页面包含文本区域嵌套在滚动面板中,一个按钮名字为显示直方图,当用户点击按钮,一个新的窗口出现,显示的是一个直方图,统计文本区域中每个字符的出现次数,下图显示的是程序运行效果。

程序实现
Main Window
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MultipleWindowDemo extends JFrame {
private JTextArea jta = new JTextArea();
private JButton jbtShowHistogram = new JButton("Show Histogram");
Histogram histogram = new Histogram();
private String content = "Write a program that creates a main window with " +
"a text area in the scroll pane and a button named \"Show Histogram\"." +
"When the user clicks the button, a new window appears that displays "+
"a histogram to show the occurrence of the letters in the text area." +
"Figure 13.31 contains a sample run of the program.";
// private String content = "编写一个程序,创建一个主窗口,页面包含文本区域嵌套在滚动面板中,一个按钮名字为显示直方图" +
// "当用户点击按钮,一个新的窗口出现,显示的是一个直方图,统计文本区域中每个字符的出现次数,图13.31显示的是程序运行效果";
// Create a new frame to hold the histogram panel
private JFrame histogramFrame = new JFrame();
public MultipleWindowDemo() throws HeadlessException {
// Store text area in a scroll pane
JScrollPane scrollPane = new JScrollPane(jta = new JTextArea()


6887

被折叠的 条评论
为什么被折叠?



