JAVA程序设计上机考试第五个题实现代码如下:
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
JA V A程序设计上机考试第五个题实现代码如下:
View包:
package view;
import java.awt.*;
import controller.*;
import javax.swing.*;
public class MainWindow extends JFrame{
//初始化变量名
public static MyPanel mypanel;
public static JPanel labelPanel;
public static JLabel jb;
public static JPanel inputPanel;
public static JLabel jlabel;
public static JTextField jtextField;
public static JPanel buttonPanel;
public MainWindow(String title, String bgImage){
setTitle(title);//设置窗体名字
//设置初始窗体大小
Dimension dim=Toolkit.getDefaultToolkit().getScreenSize();
Dimension minDim=new Dimension();
setBounds(dim.width/4,dim.height/4,dim.width/2,dim.height/2);
//设置窗体最小显示的大小
minDim.width=dim.width/2;
minDim.height=dim.height/2;
setMinimumSize(minDim);
//设置面板布局
Container contentPane=getContentPane();
contentPane.setLayout(new BorderLayout());
//获取系统字体
GraphicsEnvironment gg=GraphicsEnvironment.getLocalGraphicsEnvironment();
String ss[]=gg.getAvailableFontFamilyNames();
String systemFontName="default";
String copyrightFontName="default";
for(int i=0;i if(ss[i].equals("黑体")) systemFontName="黑体"; if(ss[i].equals("楷体")) copyrightFontName="楷体"; } mypanel=new MyPanel(bgImage);//背景图像面板 mypanel.setLayout(null);//设置背景图像面板为null布局 //组装系统名称面板systemPanel labelPanel=new JPanel(); labelPanel.setLayout(new FlowLayout()); //设置systemPanel面板对齐方式 labelPanel.setAlignmentX(CENTER_ALIGNMENT); labelPanel.setAlignmentY(CENTER_ALIGNMENT); labelPanel.setSize(520,45); int x=(this.getWidth()-labelPanel.getWidth())/2; int y=(int)(this.getHeight()*0.115); labelPanel.setLocation(x, y);//设置系统名称面板位置 labelPanel.setOpaque(false);//设置面板透明 //生成系统名称标签 JLabel systemTitle=new JLabel("请输入数据"); //设置标签字体 systemTitle.setFont(new Font(systemFontName,Font.BOLD,30)); //设置标签字体颜色 systemTitle.setForeground(Color.blue); systemTitle.setAlignmentX(CENTER_ALIGNMENT); systemTitle.setAlignmentY(CENTER_ALIGNMENT); labelPanel.add(systemTitle);//加载系统名称标签到系统名称面板 //组装输入面板inputPanel inputPanel=new JPanel(); inputPanel.setAlignmentX(CENTER_ALIGNMENT); inputPanel.setAlignmentY(CENTER_ALIGNMENT); inputPanel.setSize(320, 80); x=(this.getWidth()-inputPanel.getWidth())/2; y=this.getHeight()/2-inputPanel.getHeight(); inputPanel.setLocation(x, y);//设置输入面板位置 inputPanel.setLayout(new FlowLayout()); inputPanel.setOpaque(false); jtextField=new JTextField(15); jtextField.setSize(200,35); jtextField.setForeground(Color.blue); jtextField.setFont(new Font(systemFontName,Font.BOLD,24)); inputPanel.add(jtextField); jb=new JLabel("/21.3"); jb.setFont(new Font(systemFontName,Font.BOLD,24)); jb.setForeground(Color.blue); jb.setSize(100, 25); inputPanel.add(jb); //组装按钮面板buttonPanel buttonPanel=new JPanel(); buttonPanel.setAlignmentX(CENTER_ALIGNMENT); buttonPanel.setAlignmentY(CENTER_ALIGNMENT); buttonPanel.setSize(400, 40);