import?java.awt.*;
站在用戶的角度思考問題,與客戶深入溝通,找到元謀網(wǎng)站設(shè)計(jì)與元謀網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站建設(shè)、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、網(wǎng)站空間、企業(yè)郵箱。業(yè)務(wù)覆蓋元謀地區(qū)。
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("圓的周長(zhǎng)為:" + cir1.perimeter());
? Cylinder cy1 = new Cylinder(10, 15);
? System.out.println("圓柱體的表面積為:" + cy1.area());
? System.out.println("圓柱體的體積為:" + cy1.volume());
}
}
上面是我寫的代碼,下圖是執(zhí)行結(jié)果,麻煩看一下,是否可以。
class.forname("oracle.jdbc.driver.OracleDriver");//加載數(shù)據(jù)庫驅(qū)動(dòng)
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");//建立數(shù)據(jù)庫連接
if(!conn.isClose()){
Statement stmt = conn.createStatement();
stmt.executeUPDATE(sql); //建立一個(gè)表
}
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();
}
}
}
測(cè)試結(jié)果 :
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
實(shí)現(xiàn)思路:如果我們把九九乘法表中如“1*1=1”等式全部看作一個(gè)個(gè)整體的話,九九乘法表可看作一個(gè)直角三角形,實(shí)現(xiàn)直角三角形可用兩個(gè)for循環(huán)嵌套來實(shí)現(xiàn),那么我們最后輸出應(yīng)為System.out.print(變量1+"*"+變量2+"="+(變量1*變量2)+" ");
代碼如下:
public class ChengDemo {
public static void main(String args[]){
for(int k = 1;k=9;k++){ ? ? ? ? //外循環(huán)用于控制行數(shù) ? ? ?
for(int j = 1;j=k;j++){ ? ? ? ? ?
System.out.print(j+"*"+k+"="+(j*k)+"\t"); ? ? //"\t"為制表符
} ?
System.out.println(); ?//換行
}
}
}
java表格就是java swing。
//創(chuàng)建表頭
String[] columnNames = { "First Name", "Last Name", "Sport",
"# of Years", "Vegetarian" };
//創(chuàng)建顯示數(shù)據(jù)
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還提供了一個(gè)重載的構(gòu)造方法,傳入兩個(gè)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("數(shù)據(jù)庫url","帳號(hào)","密碼");
state=conn.createStatement();
state.executeUpdate("create 建表語句");
state.executeUpdate("insert 插入數(shù)據(jù)")------插入的值由頁面獲得,注意字符串拼接。
然后就是關(guān)閉連接,state.close();conn.close();
核心代碼就是這些,具體應(yīng)用你可以多寫幾個(gè)方法(增刪改查),都是類似的,注意異常的處理,關(guān)閉連接最好在finally中進(jìn)行。