⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comoperation.java

📁 用java编写的与单片机的串口通讯程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		 
		 /**
		 * add databit label
		 */
		 gbc.gridx = 1;
		 gbc.gridy = 2;
		 gbc.gridwidth = 1;
		 gbc.gridheight = 1;
		 gbc.fill = GridBagConstraints.NONE;
		 gbc.anchor = GridBagConstraints.NORTHWEST;
		 gbc.weightx = 1;
		 gbc.weighty = 0;
		 gbc.insets = new Insets(10, 60, 10, 15);
		 cpLayout.setConstraints(databit,gbc);
		 this.getContentPane().add(databit);
		 
		 /**
		 * add databitChoice label
		 */
		 gbc.gridx = 3;
		 gbc.gridy = 2;
		 gbc.gridwidth = 1;
		 gbc.gridheight = 1;
		 gbc.fill = GridBagConstraints.NONE;
		 gbc.anchor = GridBagConstraints.NORTHWEST;
		 gbc.weightx = 1;
		 gbc.weighty = 0;
		 gbc.insets = new Insets(10, 15, 10, 60);
		 databitChoice.addItem("8");
		 databitChoice.addItem("7");
		 databitChoice.addItem("6");
		 databitChoice.addItem("5");
		 cpLayout.setConstraints(databitChoice,gbc);
		 this.getContentPane().add(databitChoice);
		 
		 /**
		 * add stopbit label
		 */
		 gbc.gridx = 1;
		 gbc.gridy = 3;
		 gbc.gridwidth = 1;
		 gbc.gridheight = 1;
		 gbc.fill = GridBagConstraints.NONE;
		 gbc.anchor = GridBagConstraints.NORTHWEST;
		 gbc.weightx = 1;
		 gbc.weighty = 0;
		 gbc.insets = new Insets(10, 60, 10, 15);
		 cpLayout.setConstraints(stopbit,gbc);
		 this.getContentPane().add(stopbit);
		 
		 /**
		 * add stopbitChoice label
		 */
		 gbc.gridx = 3;
		 gbc.gridy = 3;
		 gbc.gridwidth = 1;
		 gbc.gridheight = 1;
		 gbc.fill = GridBagConstraints.NONE;
		 gbc.anchor = GridBagConstraints.NORTHWEST;
		 gbc.weightx = 1;
		 gbc.weighty = 0;
		 gbc.insets = new Insets(10, 15, 10, 60);
		 stopbitChoice.addItem("1");
		 stopbitChoice.addItem("1.5");
		 stopbitChoice.addItem("2");
		 cpLayout.setConstraints(stopbitChoice,gbc);
		 this.getContentPane().add(stopbitChoice);
		 
		 /**
		 * add parity label
		 */
		 gbc.gridx = 1;
		 gbc.gridy = 4;
		 gbc.gridwidth = 1;
		 gbc.gridheight = 1;
		 gbc.fill = GridBagConstraints.NONE;
		 gbc.anchor = GridBagConstraints.NORTHWEST;
		 gbc.weightx = 1;
		 gbc.weighty = 0;
		 gbc.insets = new Insets(10, 60, 10, 15);
		 cpLayout.setConstraints(parity,gbc);
		 this.getContentPane().add(parity);
		 
		 /**
		 * add parityChoice label
		 */
		 gbc.gridx = 3;
		 gbc.gridy = 4;
		 gbc.gridwidth = 1;
		 gbc.gridheight = 1;
		 gbc.fill = GridBagConstraints.NONE;
		 gbc.anchor = GridBagConstraints.NORTHWEST;
		 gbc.weightx = 1;
		 gbc.weighty = 0;
		 gbc.insets = new Insets(10, 15, 10, 60);
		 parityChoice.addItem("N");
		 parityChoice.addItem("M");
		 parityChoice.addItem("E");
		 parityChoice.addItem("O");
		 parityChoice.addItem("S");
		 cpLayout.setConstraints(parityChoice,gbc);
		 this.getContentPane().add(parityChoice);
		 
		 /**
		 * add ok button
		 */
		 gbc.gridx = 1;
		 gbc.gridy = 5;
		 gbc.gridwidth = 1;
		 gbc.gridheight = 1;
		 gbc.fill = GridBagConstraints.HORIZONTAL;
		 gbc.anchor = GridBagConstraints.NORTHWEST;
		 gbc.weightx = 1;
		 gbc.weighty = 0;
		 gbc.insets = new Insets(10, 45, 10, 50);
		 ok.addActionListener(this);
		 cpLayout.setConstraints(ok,gbc);
		 this.getContentPane().add(ok);
		 
		 /**
		 * add cancel button
		 */
		 gbc.gridx = 2;
		 gbc.gridy = 5;
		 gbc.gridwidth = 1;
		 gbc.gridheight = 1;
		 gbc.fill = GridBagConstraints.HORIZONTAL;
		 gbc.anchor = GridBagConstraints.NORTHWEST;
		 gbc.weightx = 1;
		 gbc.weighty = 0;
		 gbc.insets = new Insets(10, 15, 10, 15);
		 cancel.addActionListener(this);
		 cpLayout.setConstraints(cancel,gbc);
		 this.getContentPane().add(cancel);
		 
		 /**
		 * add exit button
		 */
		 gbc.gridx = 3;
		 gbc.gridy = 5;
		 gbc.gridwidth = 1;
		 gbc.gridheight = 1;
		 gbc.fill = GridBagConstraints.HORIZONTAL;
		 gbc.anchor = GridBagConstraints.NORTHWEST;
		 gbc.weightx = 1;
		 gbc.weighty = 0;
		 gbc.insets = new Insets(10, 50, 10, 45);
		 exit.addActionListener(this);
		 cpLayout.setConstraints(exit,gbc);
		 this.getContentPane().add(exit);
		
		 this.setSize(400,250);
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if(e.getActionCommand() == "确认")
		{
			switch(speedChoice.getSelectedIndex())
			{
				case 0:
					ComOperation.speed = 9600;
					break;
				case 1:
					ComOperation.speed = 4800;
					break;
				case 2:
					ComOperation.speed = 19200;
					break;
			}
			
			switch(databitChoice.getSelectedIndex())
			{
				case 0:
					ComOperation.databit = 8;
					break;
				case 1:
					ComOperation.databit = 7;
					break;
				case 2:
					ComOperation.databit = 6;
					break;
				case 3:
					ComOperation.databit = 5;
					break;
			}
			
			switch(stopbitChoice.getSelectedIndex())
			{
				case 0:
					ComOperation.stopbit = 1;
					break;
				case 1:
					ComOperation.stopbit = 3;
					break;
				case 2:
					ComOperation.stopbit = 2;
					break;
			}
			
			switch(parityChoice.getSelectedIndex())
			{
				case 0:
					ComOperation.parity = 0;
					break;
				case 1:
					ComOperation.parity = 3;
					break;
				case 2:
					ComOperation.parity = 2;
					break;
				case 3:
					ComOperation.parity = 1;
					break;
				case 4:
					ComOperation.parity = 4;
					break;
			}
			
		}
		if(e.getActionCommand() == "取消")
		{
			ComOperation.speed = 9600;
			ComOperation.databit = 8;
			ComOperation.stopbit = 1;
			ComOperation.parity = 0;
		}
		if(e.getActionCommand() == "退出")
		{
			this.dispose();		
		}
	}
}

class AlarmDlg extends JDialog 
{
	private Label alarm = new Label("请输入文件名!");
	
	public AlarmDlg()
	{
		this.setTitle("alarm");
		this.setSize(300,150);
		this.setModal(true);
		
		Container cp = getContentPane();
		
		GridBagLayout cpLayout = new GridBagLayout();
	    GridBagConstraints gbc = new GridBagConstraints();
		cp.setLayout(cpLayout);
		//add alarm label
		 gbc.gridx = 1;
		 gbc.gridy = 1;
		 gbc.gridwidth = GridBagConstraints.REMAINDER;
		 gbc.gridheight = 1;
		 gbc.fill = GridBagConstraints.NONE;
		 gbc.anchor = GridBagConstraints.CENTER;
		 gbc.weightx = 1;
		 gbc.weighty = 0;
		 gbc.insets = new Insets(0,5,20,10);		 
		 cpLayout.setConstraints(alarm,gbc);
		 this.getContentPane().add(alarm);		 	 
		
	}
    
}

class AlarmDlg2 extends JDialog 
{
	private Label alarm = new Label("此端口已被占用,请选择其它端口!");
	
	public AlarmDlg2()
	{
		this.setTitle("alarm");
		this.setSize(300,150);
		this.setModal(true);
		
		Container cp = getContentPane();
		
		GridBagLayout cpLayout = new GridBagLayout();
	    GridBagConstraints gbc = new GridBagConstraints();
		cp.setLayout(cpLayout);
		//add alarm label
		 gbc.gridx = 1;
		 gbc.gridy = 1;
		 gbc.gridwidth = GridBagConstraints.REMAINDER;
		 gbc.gridheight = 1;
		 gbc.fill = GridBagConstraints.NONE;
		 gbc.anchor = GridBagConstraints.CENTER;
		 gbc.weightx = 1;
		 gbc.weighty = 0;
		 gbc.insets = new Insets(0,5,20,10);		 
		 cpLayout.setConstraints(alarm,gbc);
		 this.getContentPane().add(alarm);		 	 
		
	}
    
}

		
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -