Java Swing实现多窗口

程序多窗口功能研究,代码来源于一位大佬的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.

  编写一个程序,创建一个主窗口,页面包含文本区域嵌套在滚动面板中,一个按钮名字为显示直方图,当用户点击按钮,一个新的窗口出现,显示的是一个直方图,统计文本区域中每个字符的出现次数,下图显示的是程序运行效果。

图13.31

程序实现

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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值