收藏 分销(赏)

java-Micaps实验报告.docx

上传人:仙人****88 文档编号:9281856 上传时间:2025-03-19 格式:DOCX 页数:18 大小:431.88KB
下载 相关 举报
java-Micaps实验报告.docx_第1页
第1页 / 共18页
java-Micaps实验报告.docx_第2页
第2页 / 共18页
点击查看更多>>
资源描述
南京信息工程大学 实验(实习)报告 实验(实习)名称 micaps基本功能练习 实验(实习)日期 2014.11.21 得分 指导老师 马利 系 专业 班级 姓名 学号 实验目的: 通过使用eclipse上机环境,熟悉面板构造,达到熟练编程的目的 实验内容: 一、 主面板 1.创建窗口 import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JDesktopPane; import javax.swing.JFrame; public class MainFrame { public static void main(String[] args) { new MicapsFrame(); } } class MicapsFrame extends JFrame{ JDesktopPane desktopPane; public MicapsFrame() { //设置窗体属性,采用默认的绝对布局 super(); // 设定窗体出现在屏幕的正中 // 获取屏幕的大 Dimension scrnDim = Toolkit.getDefaultToolkit().getScreenSize(); setBounds(200,100,(int)((1000.0/1280)*scrnDim.getWidth()),(int)((800.0/1024)*scrnDim.getHeight())); //设置窗体大小和位置 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);//设置窗体关闭方式 setTitle("MICAPS3");//给窗体命名 setVisible(true); //一定要设置窗体可见 java.awt.Container c=getContentPane();//窗体其实就是一个容器,获取该容器 desktopPane=new JDesktopPane();//创建桌面面板 desktopPane.setBounds(0,50,this.getSize().width,this.getSize().height-50);//设置桌面面板大小和位置 c.setLayout(null);//设置布局属性为空,即默认的绝对布局方式 } } 2.添加菜单栏按钮 JMenuBar menuBar; //给窗体添加菜单组件 menuBar=new JMenuBar(); //设置菜单栏的属性 menuBar.setBounds(0,0,this.getSize().width,20); //将菜单栏添加到容器中 c.add(menuBar); 3.添加菜单栏按钮---实现一个实例 JMenu menuFile=new JMenu("文件"); //将菜单栏的选项添加到菜单栏中 menuBar.add(menuFile); 4.添加工具栏按钮 JToolBar toolBar; //添加工具栏 toolBar=new JToolBar(); //设置工具栏不可移动 toolBar.setFloatable(false); //将工具栏添加到容器中 toolBar.setBounds(0,20,this.getSize().width,30); c.add(toolBar); 5.添加工具栏按钮------实现一个实例 JButton btn_1=new JButton(new ImageIcon("res/新建.png")); //给按钮添加提示信息 btn_1.setToolTipText("新建交互层"); //将按钮添加到工具栏中 toolBar.add(btn_1); 6.添加主面板控件 JTabbedPane paneLeft; JPanel panel; panel=new JPanel(); panel.setBounds(0,0,(int) ((200.0/1000)*this.getSize().width),this.getSize().height-50); panel.setLayout(null); //在桌面面板左边添加选项卡面板 paneLeft=new JTabbedPane(JTabbedPane.LEFT); paneLeft.setBounds(0,0,(int)((200.0/1000)*this.getSize().width),this.getSize().height-50); panel.add(paneLeft); desktopPane.add(panel); c.add(desktopPane); 7.添加左侧分裂面板 JTabbedPane paneLeft; JPanel panel; JSplitPane splitLeft; panel=new JPanel(); panel.setBounds(0,0,(int) ((200.0/1000)*this.getSize().width),this.getSize().height-50); panel.setLayout(null); //在桌面面板左边添加选项卡面板 paneLeft=new JTabbedPane(JTabbedPane.LEFT); paneLeft.setBounds(0,0,(int)((200.0/1000)*this.getSize().width),this.getSize().height-50); panel.add(paneLeft); desktopPane.add(panel); c.add(desktopPane); //图层数据控制面板 splitLeft=new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitLeft.setDividerLocation(300); JTabbedPane leftJPanel=new JTabbedPane(JTabbedPane.TOP); JScrollPane scrollTuzu=new JScrollPane(); JPanel scrollPane=new JPanel(new GridLayout(0,5)); leftJPanel.addTab("图组",scrollTuzu); leftJPanel.addTab("工具箱",scrollPane); splitLeft.setTopComponent(leftJPanel); /*splitLeft.setBottomComponent(leftJTabbedPane); */ paneLeft.addTab("",new ImageIcon("res/图层数据属性控制.png"),splitLeft); 二、 地面资料统计 1、单选框 ButtonGroup bg; bg = new ButtonGroup(); JRadioButton radiobutton6=new JRadioButton("大于等于",true); radiobutton6.setBounds(250, 50, 110, 30); radiobutton6.setFont(font); Panel.add(radiobutton6); bg.add(radiobutton6); JComboBox comboBox1=new JComboBox(new MyComboBox1()); comboBox1.setBounds(370, 50, 80, 30); Panel.add(comboBox1); JRadioButton radiobutton7=new JRadioButton("等于",false); radiobutton7.setBounds(250, 80, 80, 30); radiobutton7.setFont(font); Panel.add(radiobutton7); bg.add(radiobutton7); JRadioButton radiobutton8=new JRadioButton("小于等于",false); radiobutton8.setBounds(250, 110, 110, 30); radiobutton8.setFont(font); Panel.add(radiobutton8); bg.add(radiobutton8); 2、 下拉框 JComboBox comboBox1=new JComboBox(new MyComboBox1()); comboBox1.setBounds(370, 50, 80, 30); Panel.add(comboBox1); public class MyComboBox1 extends AbstractListModel implements ComboBoxModel{ String[] test={"全国","省份","城市"}; String selecteditem=test[0]; public Object getElementAt(int index){ return test[index]; } public int getSize(){ return test.length; } public void setSelectedItem(Object item){ selecteditem=(String)item; } public Object getSelectedItem(){ return selecteditem; } public int getIndex(){ for(int i=0;i<test.length;i++){ if(test[i].equals(getSelectedItem())) return i; break; } return 0; } } 三、 三线图 1、 创建三线图面板 setBounds(100,100,1000,700); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); setTitle("三线图"); 2、 添加分裂面板 private JSplitPane mySplitPane; private JPanel labelLeft; private JLabel lab_color_change; mySplitPane = new JSplitPane(); labelLeft = new JPanel(); labelLeft.setLayout(null); JTabbedPane myTabbedPane; myTabbedPane = new JTabbedPane(); lab_color_change = new JLabel("颜色改变实例"); lab_color_change.setBounds(50,37,200,50); labelLeft.add(lab_color_change); mySplitPane.setRightComponent(labelLeft); JPanel lab_tuxingcaozuo = new JPanel();//选项卡之一:图形操作 JPanel lab_beijingshezhi = new JPanel();//选项卡二:背景设置 myTabbedPane.addTab("图形操作", lab_tuxingcaozuo); lab_tuxingcaozuo.setLayout(null); myTabbedPane.addTab("背景设置", lab_beijingshezhi); mySplitPane.setLeftComponent(myTabbedPane); getContentPane().add(mySplitPane); mySplitPane.setDividerLocation((this.getSize().width)/5*1); 3、 添加左侧面板基本内容 JTextPane textPane = new JTextPane(); textPane.setBounds(37, 10, 106, 84); lab_tuxingcaozuo.add(textPane); JButton btnNewButton_2 = new JButton("隐现"); btnNewButton_2.setBounds(21, 117, 70, 23); lab_tuxingcaozuo.add(btnNewButton_2); JButton btnNewButton_3 = new JButton("标签"); btnNewButton_3.setBounds(101, 117, 70, 23); lab_tuxingcaozuo.add(btnNewButton_3); JButton btn_color = new JButton("颜色"); btn_color.setBounds(21, 160, 70, 23); lab_tuxingcaozuo.add(btn_color); JButton btnNewButton_5 = new JButton("宽度"); btnNewButton_5.setBounds(101, 160, 70, 23); lab_tuxingcaozuo.add(btnNewButton_5); ButtonGroup myButtonGroup = new ButtonGroup(); JRadioButton rdbtnNewRadioButton = new JRadioButton("时间轴向左",true); rdbtnNewRadioButton.setBounds(37, 214, 121, 23); myButtonGroup.add(rdbtnNewRadioButton);; lab_tuxingcaozuo.add(rdbtnNewRadioButton); JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("时间轴向右",false); rdbtnNewRadioButton_1.setBounds(37, 256, 121, 23); myButtonGroup.add(rdbtnNewRadioButton_1); lab_tuxingcaozuo.add(rdbtnNewRadioButton_1); JLabel lblNewLabel = new JLabel("时间间隔"); lblNewLabel.setBounds(31, 313, 60, 15); lab_tuxingcaozuo.add(lblNewLabel); textField = new JTextField(); textField.setBounds(94, 310, 33, 21); lab_tuxingcaozuo.add(textField); textField.setColumns(10); JLabel lblNewLabel_1 = new JLabel("小时"); lblNewLabel_1.setBounds(138, 313, 43, 15); lab_tuxingcaozuo.add(lblNewLabel_1); JCheckBox chckbxNewCheckBox = new JCheckBox("只填风"); chckbxNewCheckBox.setBounds(37, 354, 103, 23); lab_tuxingcaozuo.add(chckbxNewCheckBox); JLabel lblNewLabel_2 = new JLabel("开始时间"); lblNewLabel_2.setBounds(37, 399, 106, 15); lab_tuxingcaozuo.add(lblNewLabel_2); textField_1 = new JTextField(); textField_1.setBounds(37, 424, 106, 23); lab_tuxingcaozuo.add(textField_1); textField_1.setColumns(10); JLabel lblNewLabel_3 = new JLabel("结束时间"); lblNewLabel_3.setBounds(37, 464, 106, 15); lab_tuxingcaozuo.add(lblNewLabel_3); textField_2 = new JTextField(); textField_2.setColumns(10); textField_2.setBounds(37, 489, 106, 23); lab_tuxingcaozuo.add(textField_2); JButton btnNewButton = new JButton("存图"); btnNewButton.setBounds(21, 580, 70, 23); lab_tuxingcaozuo.add(btnNewButton); JButton btnNewButton_1 = new JButton("退出"); btnNewButton_1.setBounds(101, 580, 70, 23); lab_tuxingcaozuo.add(btnNewButton_1); 4、设置面板起始位置在屏幕正中间。 Dimension scrnDim = Toolkit.getDefaultToolkit().getScreenSize(); // 计算本窗体的起始位置 // 注意不要使用this.width和this.height来获取本窗体的宽和高 // 不然计算位置不在屏幕中央,原因可能是因为pack方法的影响 // getSize方法可能重新计算了pack后的窗体大小 int x = (scrnDim.width - this.getSize().width) / 2; int y = (scrnDim.height - this.getSize().height) / 2; this.setLocation(x, y); 5、 添加事件监听。 btn_color.addActionListener(this);//设置颜色事件监听器,当出现点击,触发 public void stateChanged(ChangeEvent e) { Color selectedColor_background=jcc_background.getColor(); Color selectedColor_text=jcc_text.getColor(); labelLeft.setBackground(selectedColor_background); lab_color_change.setForeground(selectedColor_text); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub // TODO Auto-generated method stub //事件发生捕捉 String evtCmd=e.getActionCommand(); if(evtCmd.equals("颜色")){ event_handle_color(); } } private void event_handle_color(){ JDialog dlg=new javax.swing.JDialog(); dlg.setBounds(400, 100, 100, 50); dlg.setTitle("颜色"); //作为独立的颜色选择器,可以给其构造器一个初始颜色 jcc_background.getSelectionModel().addChangeListener(this); jcc_text.getSelectionModel().addChangeListener(this); Container c=dlg.getContentPane(); JTabbedPane myColorTabbedPane=new JTabbedPane();//声明一个选项卡面板 JPanel background_Color=new JPanel(); JPanel text_color=new JPanel(); myColorTabbedPane.addTab("背景颜色设置", background_Color); myColorTabbedPane.addTab("文字颜色设置",text_color); background_Color.add(jcc_background,BorderLayout.CENTER); text_color.add(jcc_text,BorderLayout.CENTER); c.add(myColorTabbedPane); dlg.pack(); dlg.setVisible(true); dlg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); } 实验感悟: 通过这几次的上机实验,我学会了使用eclipse设计关于micaps的一些基本功能,还有面板的布局,以及一些面板上基本的原件之间的关系。对编程的了解更加深了,也更熟悉java语言吗,对我以后的学习帮助很大。
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服