欢迎来到天天文库
浏览记录
ID:14658655
大小:330.00 KB
页数:26页
时间:2018-07-29
《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(50
2、0,500);DimensionscreenSize=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.setVi
3、sible(true);}}packageStatistics_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.swin
4、g.Box;importjavax.swing.BoxLayout;importjavax.swing.JButton;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JTextField;publicclassAeiouPanelextendsJPanel{privateJLabelinput,label1,label2,label3,label4,label5,label6;privateJTextFieldtext;privateJButtons
5、ure,exit;privateJPanelpanel,panel1;privatefinalintN=60,WITH=30;publicAeiouPanel(){input=newJLabel("InputCharacter:");text=newJTextField(15);sure=newJButton("确定");exit=newJButton("退出");panel=newJPanel();panel1=newJPanel();label1=newJLabel("a:");label2=newJLabel("e:");label
6、3=newJLabel("i:");label4=newJLabel("o:");label5=newJLabel("u:");label6=newJLabel("其它字符:");AeiouListenerlistener=newAeiouListener();sure.addActionListener(listener);exit.addActionListener(listener);panel.setLayout(newFlowLayout());panel.setBackground(Color.cyan);panel.add(
7、input);panel.add(text);panel.add(sure);panel.add(exit);panel1.setLayout(newBoxLayout(panel1,BoxLayout.Y_AXIS));panel1.setBackground(Color.cyan);panel1.add(label1);panel1.add(Box.createRigidArea(newDimension(0,20)));panel1.add(label2);panel1.add(Box.createRigidArea(newDime
8、nsion(0,20)));panel1.add(label3);panel1.add(Box.createRigidArea(newDimension(0,20)));panel1.add(
此文档下载收益归作者所有