随笔分类 - java基础
java基础
摘要:import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.net.URL;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.KeyStroke;
public c
阅读全文
摘要:import java.awt.BorderLayout;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class JTabbedPaneTest extends JFrame {
public JTabbedPaneTest()
{
super();
setTitle("表格");
setBounds(100,100,350,150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//final JTabbedPane tabbedPane = new JTabbedPane(
阅读全文
摘要:import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.filechooser.*;
import javax.swing.*;
public class JProgressBarTest extends JFrame{
public JProgressBarTest() {
super();
setTitle("表格");
setBounds(100,100,350,150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JBu
阅读全文
摘要:import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
public class JPopupMenuTest extends JFrame{
public JPopupMenuTest()
{
super();
setTitle("MenuTest
阅读全文
摘要:import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class JInternalFrameTest extends JFrame{
JDesktopPane desktopPane = null; //桌面面板
InternalFrame plnF
阅读全文
摘要:import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.filechooser.*;
import javax.swing.*;
public class JFileF
阅读全文
摘要:import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JSplitPane;
import javax.swing.JToolBar;
public class JFileChooserTest extends JFrame{
public JFileChooserTest()
{
super();
s
阅读全文
摘要:import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
public class JTreeTest extends JFrame{
public JTreeTest()
{
super();
setTitle("Swing树组件");
setBounds(100,100,350,150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DefaultMutableTreeNode root = new DefaultMutableTreeNode("根节点");
DefaultMutableTreeNode nodeFirst = new DefaultMutableTreeNode("
阅读全文
摘要:import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
//维护表格
public class JTableDefa
阅读全文
摘要:import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class JTableOperation extends JFrame {
public JTableOperation()
{
super();
setTitle("表格");
setBounds(100,100,500,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JScrollPane scrollPane = new
阅读全文
摘要:import java.awt.BorderLayout;
import java.awt.Color;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
public class JTableDefineTest extends JFrame{
public JTableDefineTest()
{
super();
setTitle("表格");
setBounds(100,100,500,500);
setDefau
阅读全文
摘要:import java.awt.BorderLayout;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;
public class JTableTest2 extends JFrame{
public JTableTest2()
{
super();
setTitle("表格");
setBounds(100,100,240,150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Vector columnNameV = new Vector();
columnNameV.add("A");
columnNameV.add("B");
Vector tableValueV = new Vector();
for(int row=1;row6;row++)
{
阅读全文
摘要:import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class JTableTest extends JFrame {
public JTableTest()
{
super();
setTitle("表格");
setBounds(100,100,240,150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String[] columnNames = {"A","B"}; //列名
String [][]tableVales={{"A1","B1"},{"A2","B2"},{"A3","B3"},{"A4","B4"},{"A5","B5"}}; //数据
JTable table = new JTable(tableVales,columnNames); //生成
阅读全文
摘要:import java.net.URLDecoder;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ResultSetLike {
/**
* 取得相对路径的Connection
* @return
*/
public static Connection getConnection(){
Connection conn=null;
try{
String path="";
Class theClass = ResultSetLike.class;
//System.out.println(ConnTest2.class.getResourceAsStream("db.mdb"));
阅读全文
摘要:import java.net.URLDecoder;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class PrepareStatementTest {
/**
* 取得相对路径的Connection
* @return
*/
public static Connection getConnection(){
Connection conn=null;
try{
String path="";
Class theClass = PrepareStatementTest.class;
//System.out.println(ConnTes
阅读全文
摘要:/**
* 取得相对路径的Connection
* @return
*/
public static Connection getConnection(){
Connection conn=null;
try{
String path="";
Class theClass = ConnTest2.class;
//System.out.println(ConnTest2.class.getResourceAsStream("db.mdb"));
java.net.URL u= theClass.getResource("db.mdb");
String ChinesePath = URLDecoder.decode(u.getPath().substring(1,u.getPath().length()).replaceAll("%20", " "),"UTF-8");
//System.out.prin
阅读全文
摘要:import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ConnAccessTest {
Connection con;
String DBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String ConnStr = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=E:/workspace/Java从入门到精通/src/第20章数据库操作/db.mdb";
//String ConnStr = "jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=E:/workspace/db.mdb";
Conne
阅读全文
摘要:
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class AnnotationTest {
@Field_Method_Parameter_Annotation(describ="字段编号",type=int.class) //注释字段
int id;
@Field_Method_Parameter_Annotation(describ="字段姓名",type=String.class)//注释字段
String name;
@Constructor_Annotation()//采用默认构造方法
public AnnotationTest()
{
}
@Constructor_Annotation("立即初始化构造方法.") //注释构造方法
public
阅读全文
摘要:import java.lang.reflect.Field;
public class FieldTest {
int i;
public float f;
protected boolean b;
private String s;
public FieldTest()
{
i=0;
f=0.0f;
b = true;
s = "";
}
public static void main(String[] args){
//进行类实例化:
FieldTest fieldTest = new FieldTest();
Field[] declaredFields = FieldTest.class.getDeclaredFields();
for(int i=0;ideclaredFields.length;i++){
Field field = declaredFields[i];
System.out.println("名称为:"+field.getName(
阅读全文
摘要:import java.lang.reflect.Method;
/**
* @author Administrator
*
*/
public class MethodTest {
static void staticMethod()
{
System.out.println("执行staticMethod()方法");
}
public int publicMethod(int i)
{
System.out.println("执行publicMethod()方法");
return i*20;
}
protected int protectedMethod(String s,int i) throws NumberFormatException{
System.out.println("执行protectedMethod()方法");
return Integer.valueOf(s)+i;
}
private String privateMethod(String...strings){
阅读全文