java cardlayout应用
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class lab extends JFrame{
static Button [] b=new Button[5];
static JFrame f=new JFrame("lab");
static JPanel [] p=new JPanel[5];
static JPanel s=new JPanel();
static JPanel t=new JPanel();
static CardLayout cl= new CardLayout();
static class ActionHandler implements ActionListener
{
int w;
public ActionHandler(int i) {
w=i;
}
public void actionPerformed(ActionEvent e) {
cl.show(t, String.valueOf(w));
}
}
public static void main(String[] args)
{
s.setLayout(new GridLayout(1,5));
for(int i=0;i<5;i++)
{
ActionListener a=new ActionHandler(i);
b[i]=new Button("Button_"+(i+1));
b[i].addActionListener(a);
s.add(b[i]);
}
t.setLayout(cl);
for(int i=0;i<5;i++)
{
p[i]=new JPanel();
p[i].add(new Label("this is the context of Button"+(i+1)));
Color c=new Color((int)(Math.random()*250),(int)(Math.random()*250),(int)(Math.random()*250));
p[i].setBackground(c);
t.add(String.valueOf(i) ,p[i]);
}
f.add(s,BorderLayout.NORTH);
f.add(t,Bor
相关文档:
1、语法:必须比较熟悉,在写代码的时候IDE的编辑器对某一行报错应该能够根据报错信息知道是什么样的语法错误并且知道任何修正。
2、命令:必须熟悉JDK带的一些常用命令及其常用选项,命令至少需要熟悉:appletviewer、 HtmlConverter、jar、 java、javac、javadoc、javap、javaw、 ......
定义:
GOF《设计模式》中给状态模式下的定义为:允许一个对象在其内部状态改变时改变它的行为。
先看一个例子:
package com.state;
public class KissingPrincess {
// 标志位,标志是青蛙还是王子。
private boolean isFrog = true;
// 根据isFrog进行不同的操作。
public void greet() {
if (isFrog)
......
一、建表
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`ID` int(11) NOT NULL auto_increment,
`NAME` varchar(16) NOT NULL default '',
`REMARK` varchar(16) NOT NULL default '',
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8;
&nb ......
首先,打开MySQL Query Browser,在当前Test数据库下,新建一个student表,有如下属性:
create table student (name varchar(10),id int(2),sex varchar(10));
程序见下:
package com.JDBC;
import java.sql.*;
public class JDBCTest {
public static void main(String[] args) {String driver = "com.mys ......