欢迎来到天天文库
浏览记录
ID:18428798
大小:330.00 KB
页数:26页
时间:2018-09-17
《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_CL
2、OSE);frame.setSize(500,500);DimensionscreenSize=Toolkit.getDefaultToolkit().getScreenSize();intx=(screenSize.width-frame.getWidth())/2;inty=(screenSize.height-frame.getHeight())/2;frame.setLocation(x,y);AeiouPanelpanel=newAeiouPanel();frame.getContent
3、Pane().add(panel);frame.pack();frame.setVisible(true);}}packageStatistics_aeiou;importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Component;importjava.awt.Dimension;importjava.awt.FlowLayout;importjava.awt.Graphics;importjava.awt.event.A
4、ctionEvent;importjava.awt.event.ActionListener;importjavax.swing.Box;importjavax.swing.BoxLayout;importjavax.swing.JButton;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JTextField;publicclassAeiouPanelextendsJPanel{privateJLabeli
5、nput,label1,label2,label3,label4,label5,label6;privateJTextFieldtext;privateJButtonsure,exit;privateJPanelpanel,panel1;privatefinalintN=60,WITH=30;publicAeiouPanel(){input=newJLabel("InputCharacter:");text=newJTextField(15);sure=newJButton("确定");exit=
6、newJButton("退出");panel=newJPanel();panel1=newJPanel();label1=newJLabel("a:");label2=newJLabel("e:");label3=newJLabel("i:");label4=newJLabel("o:");label5=newJLabel("u:");label6=newJLabel("其它字符:");AeiouListenerlistener=newAeiouListener();sure.addActionL
7、istener(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,BoxLayout.Y_AXIS));panel1.setBack
8、ground(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(
此文档下载收益归作者所有