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

📄 test.java

📁 java jdbc直连作业。欢迎大家参考参考。
💻 JAVA
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


class Start
{
	public static void main(String[] args)
	{
		JFrame mf=new MyFrame();
		mf.setSize(500,500);
		mf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		mf.setVisible(true);
		System.out.println(JFrame.EXIT_ON_CLOSE);
		
	}
}

class MyFrame extends JFrame
{
	Container c=null;
	JPanel mp=null;//struct JPanel* mp=NULL;
 	public MyFrame()
 	{
 			c=this.getContentPane();//获取那块合适的幕
 			mp=new MyPanel();//准备一块画布
 		 	c.add(mp);//在合适的幕上将画布放上去。
 	}

}
class MyPanel extends JPanel
{
	Student[] stus=new Student[5];
	int count=0;
	JTextField txtStuNo=new JTextField(10);
	JTextField txtStuName=new JTextField(10);
	JTextField txtStuAge=new JTextField(10);
	JTextField txtClass=new JTextField(10);
	
	JLabel labStuNo=new JLabel("StuNo");
	JLabel labStuName=new JLabel("StuName");
	JLabel labStuAge=new JLabel("StuAge");
	JLabel labClass=new JLabel("ClassName");

	JButton but=new JButton("录入");
	JButton but2=new JButton("查询全部");
	public MyPanel()
	{
		this.add(labStuNo);
		this.add(txtStuNo);
		
		this.add(labStuName);
		this.add(txtStuName);
		
		this.add(labStuAge);
		this.add(txtStuAge);
		
		this.add(labClass);
		this.add(txtClass);

		this.add(but);
		this.add(but2);
		but.addActionListener(new MyL());
		but2.addActionListener(new MyL2());
	}
	class MyL implements ActionListener
	{
	   public void actionPerformed(ActionEvent e)
	   {
	   	        try
	   	        {Student stu=new Student();
	   	        stu.setStuNo(txtStuNo.getText());
	   	        stu.setStuName(txtStuName.getText());
	   	        stu.setAge(Short.parseShort(txtStuAge.getText()));
	   	        stu.setClassName(txtClass.getText());
	   	        stus[count++]=stu;
	   	       
	   	        JOptionPane.showMessageDialog(null,"录入完毕");
	   	        txtStuNo.setText("");
	   	        txtStuName.setText("");
	   	        txtStuAge.setText("");
	   	        txtClass.setText("");
	   	       }catch(IllegalArgumentException i)
	   	       {
	   	       		JOptionPane.showMessageDialog(null,"error");
	   	       		txtStuAge.setText("");
	   	    
	   	       }
	   	        
	   	      //  JOptionPane.showMessageDialog(null,stu.getStuNo()+"  " +stu.getStuName() +"  "+stu.getStuAge()+ " " +stu.getClassName());
	   	          
	   }
	}
	
	class MyL2 implements ActionListener
	{
	   public void actionPerformed(ActionEvent e)
	   {
	   		for(int i=0;i<count;i++)
	   		{
	   			System.out.println(stus[i].getStuNo()+"  " +stus[i].getStuName() +"  "+stus[i].getStuAge()+ " " +stus[i].getClassName());
	   		}
	   	}
	}
	}

class Student
{
	private String stuNo;
	private String stuName;
	private String className;
	private short stuAge;

  	public void setStuNo(String _stuNo)
	{
		this.stuNo=_stuNo;
	}
	public String getStuNo()
	{
		return this.stuNo;
	}
	public void setStuName(String _stuName)
	{
		this.stuName=_stuName;
	}
	public String getStuName()
	{
		return this.stuName;
	}
	
	public String getClassName()
	{
		return this.className;
	}
	public void setClassName(String _className)
	{
		this.className=_className;
	}
	public int getStuAge()
	{
		return this.stuAge;
	}
	public void setAge(short _age) 
	{
		try
		{
			if(_age>0 && _age<150)
		    this.stuAge=_age;
		    else
		    {throw new IllegalArgumentException();
		    
		    }
		    
		}catch(java.lang.IllegalArgumentException i)
		{
			System.out.println("error");
			throw i;
		}
	}

}

⌨️ 快捷键说明

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