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

📄 addinforframe.java

📁 含有图形化界面
💻 JAVA
字号:
package com.zsf.manager;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.sql.SQLException;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;


class AddInforFrame extends JFrame{
	private static final long serialVersionUID = 1L;

	JPanel p1=new JPanel();
	JPanel p2=new JPanel();
	JPanel p2_1=new JPanel();		
	JPanel p2_2=new JPanel();		
	JPanel p2_3=new JPanel();		
	JPanel p3=new JPanel();
	
	ButtonGroup bg= new ButtonGroup();
	JRadioButton rb1=new JRadioButton("Family");
	JRadioButton rb2=new JRadioButton("Friends");
	JRadioButton rb3=new JRadioButton("Music");
	JRadioButton rb4=new JRadioButton("Work");
	
	JLabel lb1=new JLabel("FirstName");
	JLabel lb2=new JLabel("LastName");
	JLabel lb3=new JLabel("Telephone");
	JTextField t1=new JTextField();
	JTextField t2=new JTextField();
	JTextField t3=new JTextField();
	
	JButton b1=new JButton("Save");
	JButton b2=new JButton("Exit");
	public AddInforFrame()
	{	
		p2_1.setLayout(new BorderLayout());
		p2_2.setLayout(new BorderLayout());
		p2_3.setLayout(new BorderLayout());		
		
		bg.add(rb1);
		bg.add(rb2);
		bg.add(rb3);
		bg.add(rb4);		
				
		p1.add(rb1);
		p1.add(rb2);
		p1.add(rb3);
		p1.add(rb4);
			
		p2_1.add(lb1,BorderLayout.NORTH);
		p2_1.add(new JLabel("   "),BorderLayout.CENTER);
		p2_1.add(t1,BorderLayout.SOUTH);
		
		p2_2.add(lb2,BorderLayout.NORTH);
		p2_2.add(new JLabel("   "),BorderLayout.CENTER);
		p2_2.add(t2,BorderLayout.SOUTH);
		
		p2_3.add(lb3,BorderLayout.NORTH);
		p2_3.add(new JLabel("    "),BorderLayout.CENTER);
		p2_3.add(t3,BorderLayout.SOUTH);
		
		p2.add(p2_1,FlowLayout.LEFT);
		p2.add(p2_2,FlowLayout.CENTER);
		p2.add(p2_3,FlowLayout.RIGHT);
		
		p3.add(b1);
		p3.add(b2);
		
		rb1.setSelected(true);
		this.add(p1,BorderLayout.NORTH);
		this.add(p2,BorderLayout.CENTER);
		this.add(p3,BorderLayout.SOUTH);
		
		this.setSize(300, 200);
		this.setVisible(true);
		this.eventRun();
	}
	
	public void eventRun()
	{
		new ButtonHandleInInforFrame(b1,this);
		new ButtonHandleInInforFrame(b2,this);
	}
	
	public void Save()
	{
		RadioButtonHandle rbh1=new RadioButtonHandle(rb1);
		RadioButtonHandle rbh2=new RadioButtonHandle(rb2);
		RadioButtonHandle rbh3=new RadioButtonHandle(rb3);
		RadioButtonHandle rbh4=new RadioButtonHandle(rb4);
		
		if(t1.getText()!=null&&t1.getText().length()>1){
			if(t2.getText()!=null&&t2.getText().length()>1){
				if(t3.getText()!=null&&t3.getText().length()>1){
					PostDB postdb=new PostDB(new MyDB());
					Post post =new Post();
					post.setfirstname(t1.getText());
					post.setlastname(t2.getText());
					post.settelephone(t3.getText());
					if(rb1.isSelected())
						post.setrole(rbh1.initRole());
					else if(rb2.isSelected())
						post.setrole(rbh2.initRole());
					else if(rb3.isSelected())
						post.setrole(rbh3.initRole());
					else 
						post.setrole(rbh4.initRole());
					
					try {
						postdb.savePost(post);
						this.MessageDialog(JOptionPane.NO_OPTION, 
								"Add successfully!", "Congrutulations");
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				else{
					this.MessageDialog(JOptionPane.ERROR_MESSAGE, 
							"Telephone is null", "Warning");
				}
			}else{
				this.MessageDialog(JOptionPane.ERROR_MESSAGE,
						"LastName is null", "Warning");
			}				
		}else{			
			this.MessageDialog(JOptionPane.ERROR_MESSAGE, 
					"FirstName is null", "Warning");
		}
	}
	public void MessageDialog(int temp,String message,String title)
	{
		JOptionPane.showMessageDialog(this, message,title,temp);
	}
	
}

⌨️ 快捷键说明

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