import java.awt.*;
站在用户的角度思考问题,与客户深入沟通,找到元谋网站设计与元谋网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站建设、成都做网站、企业官网、英文网站、手机端网站、网站推广、空间域名、网站空间、企业邮箱。业务覆盖元谋地区。
import java.awt.event.*;
import javax.swing.*;
public class JListDemo extends JFrame {
private JPanel topPanel;
private JList listbox;
public JListDemo(){
setTitle( "Simple ListBox Application" );
setSize( 300, 100 );
setBackground( Color.gray );
topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
String listData[] =
{
"Item 1",
"Item 2",
"Item 3",
"Item 4"
};
listbox = new JList( listData );
topPanel.add( listbox, BorderLayout.CENTER );
}
public static void main( String args[] ) {
JListDemo mainFrame = new JListDemo();
mainFrame.setVisible( true );
}
}
Shape.java接口代码
public interface Shape {
public static final double PI = 3.14d;
public double area();
}
Circle.java圆类代码
public class Circle implements Shape {
private double radius;
public Circle(double radius) {
this.radius = radius;
}
@Override
public double area() {
return PI * this.radius * this.radius;
}
public double perimeter() {
return 2 * PI * this.radius;
}
}
Cylinder.java圆柱体类代码
public class Cylinder extends Circle {
private double height;
public Cylinder(double radius, double height) {
super(radius);
this.height = height;
}
public double area() {
return 2 * super.area() + super.perimeter() * this.height;
}
public double volume() {
return super.area() * this.height;
}
}
X5_3_6.java主类代码
public class X5_3_6 {
public static void main(String[] args) {
Circle cir1 = new Circle(5);
System.out.println("圆的面积为:" + cir1.area());
System.out.println("圆的周长为:" + cir1.perimeter());
Cylinder cy1 = new Cylinder(10, 15);
System.out.println("圆柱体的表面积为:" + cy1.area());
System.out.println("圆柱体的体积为:" + cy1.volume());
}
}
上面是我写的代码,下图是执行结果,麻烦看一下,是否可以。
class.forname("oracle.jdbc.driver.OracleDriver");//加载数据库驱动
String url="jdbc:oracle:thin:@localhost:1521:db_name";
String sql="CREATE TABLE table(filed1 varchar2(2),filed2 varchar2(2))";
Connection conn=DriverManager.getConnection(url,"scott","tiger");//建立数据库连接
if(!conn.isClose()){
Statement stmt = conn.createStatement();
stmt.executeUPDATE(sql); //建立一个表
}
package ch02;
public class TEST{
public static void main(String[] args) {
for (int i = 1; i =9; i++) {
for (int j = 1; j = i; j++) {
System.out.print(j+"*"+i+"="+(i*j)+" ");
}System.out.println();
}
}
}
测试结果 :
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
1*4=4 2*4=8 3*4=12 4*4=16
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64
1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81
实现思路:如果我们把九九乘法表中如“1*1=1”等式全部看作一个个整体的话,九九乘法表可看作一个直角三角形,实现直角三角形可用两个for循环嵌套来实现,那么我们最后输出应为System.out.print(变量1+"*"+变量2+"="+(变量1*变量2)+" ");
代码如下:
public class ChengDemo {
public static void main(String args[]){
for(int k = 1;k=9;k++){ //外循环用于控制行数
for(int j = 1;j=k;j++){
System.out.print(j+"*"+k+"="+(j*k)+"\t"); //"\t"为制表符
}
System.out.println(); //换行
}
}
}
java表格就是java swing。
//创建表头
String[] columnNames = { "First Name", "Last Name", "Sport",
"# of Years", "Vegetarian" };
//创建显示数据
Object[][] data = {
{ "Kathy", "Smith", "Snowboarding", new Integer(5),
new Boolean(false) },
{ "John", "Doe", "Rowing", new Integer(3), new Boolean(true) },
{ "Sue", "Black", "Knitting", new Integer(2),
new Boolean(false) },
{ "Jane", "White", "Speed reading", new Integer(20),
new Boolean(true) },
{ "Joe", "Brown", "Pool", new Integer(10), new Boolean(false) } };
/*
* JTable还提供了一个重载的构造方法,传入两个Vector
* JTable(Vector rowData, Vector columnNames)
*
*/
final JTable table = new JTable(data, columnNames);
table.setBackground(Color.YELLOW);
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("数据库url","帐号","密码");
state=conn.createStatement();
state.executeUpdate("create 建表语句");
state.executeUpdate("insert 插入数据")------插入的值由页面获得,注意字符串拼接。
然后就是关闭连接,state.close();conn.close();
核心代码就是这些,具体应用你可以多写几个方法(增删改查),都是类似的,注意异常的处理,关闭连接最好在finally中进行。