欢迎来到天天文库
浏览记录
ID:18601434
大小:330.00 KB
页数:26页
时间:2018-09-19
《java程序设计教程部分答案3》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Pp5.15统计元音字母个数packageStatistics_aeiou;importjava.awt.Dimension;importjava.awt.Toolkit;importjavax.swing.JFrame;publicclassStatistics{publicstaticvoidmain(String[]args){JFrameframe=newJFrame("元音字母统计柱状图");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setSize(500,500);Dimension
2、screenSize=Toolkit.getDefaultToolkit().getScreenSize();intx=(screenSize.width-frame.getWidth())/2;inty=(screenSize.height-frame.getHeight())/2;frame.setLocation(x,y);AeiouPanelpanel=newAeiouPanel();frame.getContentPane().add(panel);frame.pack();frame.setVisible(true);}}packageStatistics_
3、aeiou;importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Component;importjava.awt.Dimension;importjava.awt.FlowLayout;importjava.awt.Graphics;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.Box;importjavax.swing.BoxLayout;importjavax.sw
4、ing.JButton;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JTextField;publicclassAeiouPanelextendsJPanel{privateJLabelinput,label1,label2,label3,label4,label5,label6;privateJTextFieldtext;privateJButtonsure,exit;privateJPanelpanel,panel1;privatefinalintN=60,WITH=30;p
5、ublicAeiouPanel(){input=newJLabel("InputCharacter:");text=newJTextField(15);sure=newJButton("确定");exit=newJButton("退出");panel=newJPanel();panel1=newJPanel();label1=newJLabel("a:");label2=newJLabel("e:");label3=newJLabel("i:");label4=newJLabel("o:");label5=newJLabel("u:");label6=newJLabel
6、("其它字符:");AeiouListenerlistener=newAeiouListener();sure.addActionListener(listener);exit.addActionListener(listener);panel.setLayout(newFlowLayout());panel.setBackground(Color.cyan);panel.add(input);panel.add(text);panel.add(sure);panel.add(exit);panel1.setLayout(newBoxLayout(panel1,BoxL
7、ayout.Y_AXIS));panel1.setBackground(Color.cyan);panel1.add(label1);panel1.add(Box.createRigidArea(newDimension(0,20)));panel1.add(label2);panel1.add(Box.createRigidArea(newDimension(0,20)));panel1.add(label3);panel1.add(Box.createRigidArea(newDimension(0,20)));panel1.add(
此文档下载收益归作者所有