導航:首頁 > 源碼編譯 > java物聯源碼

java物聯源碼

發布時間:2024-03-04 19:29:53

『壹』 如何在Eclipse中查看java類庫的源代碼以及相應的api

在Eclipse中查看Java類庫的源代碼,可以通過Ctrl+滑鼠左鍵的方式來完成;在下載JDK並安裝的時候,會有一個src.zip文件,此文件就是Java類庫的源碼。但是有時候,會出現源碼未找到的問題,此時可以通過對其設置來解決。

  1. 以JDK1.8為例,查看一下src.zip文件


    注意:下載之後的zip文件,解壓之後都是英文狀態的幫助文檔!


『貳』 java小程序源代碼,簡單點的,100多行,誰有啊

// My car shop.java

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.border.*;

public class carshop extends JFrame
{
// JPanel to hold all pictures
private JPanel windowJPanel;
private String[] cars = { "","阿斯頓馬丁", "美洲虎", "凱迪拉克",
"羅孚", "勞斯萊斯","別克"};
private int[] jiage = { 0,150000, 260000, 230000,
140000, 290000, 150000};
// JLabels for first snack shown
private JLabel oneJLabel;
private JLabel oneIconJLabel;

// JLabels for second snack shown
private JLabel twoJLabel;
private JLabel twoIconJLabel;

// JLabels for third snack shown
private JLabel threeJLabel;
private JLabel threeIconJLabel;

// JLabels for fourth snack shown
private JLabel fourJLabel;
private JLabel fourIconJLabel;

// JLabels for fifth snack shown
private JLabel fiveJLabel;
private JLabel fiveIconJLabel;

// JLabels for sixth snack shown
private JLabel sixJLabel;
private JLabel sixIconJLabel;

// JTextField for displaying snack price
private JTextArea displayJTextArea;

// JLabel and JTextField for user input
private JLabel inputJLabel;
private JComboBox selectCountryJComboBox;

private JLabel inputJLabel2;
private JTextField inputJTextField2;

// JButton to enter user input
private JButton enterJButton;

//JButton to clear the components
private JButton clearJButton;

// no-argument constructor
public carshop()
{
createUserInterface();
}

// create and position GUI components; register event handlers
private void createUserInterface()
{
// get content pane for attaching GUI components
Container contentPane = getContentPane();

// enable explicit positioning of GUI components
contentPane.setLayout( null );

// set up windowJPanel
windowJPanel = new JPanel();
windowJPanel.setBounds( 10, 20, 340, 200 );
windowJPanel.setBorder( new LineBorder( Color.BLACK ) );
windowJPanel.setLayout( null );
contentPane.add( windowJPanel );

// set up oneIconJLabel
oneIconJLabel = new JLabel();
oneIconJLabel.setBounds( 10, 20, 100, 65 );
oneIconJLabel.setIcon( new ImageIcon( "images/阿斯頓馬丁.jpg" ) );
windowJPanel.add( oneIconJLabel );

// set up oneJLabel
oneJLabel = new JLabel();
oneJLabel.setBounds( 10, 60, 100, 70 );
oneJLabel.setText( "阿斯頓馬丁" );
oneJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( oneJLabel );

// set up twoIconJLabel
twoIconJLabel = new JLabel();
twoIconJLabel.setBounds( 120, 20, 100, 65 );
twoIconJLabel.setIcon( new ImageIcon( "images/美洲虎.jpg" ) );
windowJPanel.add( twoIconJLabel );

// set up twoJLabel
twoJLabel = new JLabel();
twoJLabel.setBounds( 110, 60, 100, 70 );
twoJLabel.setText( "美洲虎" );
twoJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( twoJLabel );

// set up threeIconJLabel
threeIconJLabel = new JLabel();
threeIconJLabel.setBounds( 230, 20, 100, 65 );
threeIconJLabel.setIcon( new ImageIcon(
"images/凱迪拉克.jpg" ) );
windowJPanel.add( threeIconJLabel );

// set up threeJLabel
threeJLabel = new JLabel();
threeJLabel.setBounds( 230, 60, 100, 70);
threeJLabel.setText( "凱迪拉克" );
threeJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( threeJLabel );

// set up fourIconJLabel
fourIconJLabel = new JLabel();
fourIconJLabel.setBounds( 10, 100, 100, 65 );
fourIconJLabel.setIcon( new ImageIcon( "images/羅孚.jpg" ) );
windowJPanel.add( fourIconJLabel );

// set up fourJLabel
fourJLabel = new JLabel();
fourJLabel.setBounds( 10, 150, 50, 70 );
fourJLabel.setText( "羅孚" );
fourJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( fourJLabel );

// set up fiveIconJLabel
fiveIconJLabel = new JLabel();
fiveIconJLabel.setBounds( 120, 100, 100, 65 );
fiveIconJLabel.setIcon( new ImageIcon(
"images/勞斯萊斯.jpg" ) );
windowJPanel.add( fiveIconJLabel );

// set up fiveJLabel
fiveJLabel = new JLabel();
fiveJLabel.setBounds( 110, 150, 100, 70 );
fiveJLabel.setText( "勞斯萊斯" );
fiveJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( fiveJLabel );

// set up sixIconJLabel
sixIconJLabel = new JLabel();
sixIconJLabel.setBounds( 230, 100, 100, 65 );
sixIconJLabel.setIcon( new ImageIcon( "images/別克.jpg" ) );
windowJPanel.add( sixIconJLabel );

// set up sixJLabel
sixJLabel = new JLabel();
sixJLabel.setBounds( 230, 150, 100, 70 );
sixJLabel.setText( "別克" );
sixJLabel.setHorizontalAlignment( JLabel.CENTER );
windowJPanel.add( sixJLabel );

// set up enterJButton
enterJButton = new JButton();
enterJButton.setBounds( 390, 160, 135, 30 );
enterJButton.setText( "Enter" );
contentPane.add( enterJButton );
enterJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// event handler called when enterJButton is clicked
public void actionPerformed( ActionEvent event )
{
enterJButtonActionPerformed( event );
}

} // end anonymous inner class

); // end call to addActionListener

// set up clearJButton
clearJButton = new JButton();
clearJButton.setBounds( 390, 200, 135, 30 );
clearJButton.setText( "Clear" );

contentPane.add( clearJButton );

// set up inputJLabel

inputJLabel = new JLabel();
inputJLabel.setBounds( 390, 25, 135, 25 );
inputJLabel.setText( "Please make selection:" );
contentPane.add( inputJLabel );

selectCountryJComboBox = new JComboBox( cars );
selectCountryJComboBox.setBounds( 390, 50, 135, 21 );
selectCountryJComboBox.setMaximumRowCount( 3 );
contentPane.add( selectCountryJComboBox );
// set up inputJTextField

inputJLabel2 = new JLabel();
inputJLabel2.setBounds( 390, 80, 150, 20 );
inputJLabel2.setText( "Input the Numble:" );
contentPane.add( inputJLabel2 );

// set up inputJTextField
inputJTextField2 = new JTextField();
inputJTextField2.setBounds( 390, 100, 135, 25 );
inputJTextField2.setHorizontalAlignment( JTextField.RIGHT );
contentPane.add( inputJTextField2 );

clearJButton.addActionListener(

new ActionListener() // anonymous inner class
{
// event handler called when clearJButton is clicked
public void actionPerformed( ActionEvent event )
{
clearJButtonActionPerformed( event );
}

} // end anonymous inner class
);

// set up displayJTextField
displayJTextArea = new JTextArea();
displayJTextArea.setBounds( 10, 237,515, 70 );
displayJTextArea.setEditable( false );
contentPane.add( displayJTextArea );
// set properties of application's window
setTitle( "My car Shop" ); // set title bar string
setSize( 550, 360 ); // set window size
setVisible( true ); // display window

} // end method createUserInterface

private void clearJButtonActionPerformed( ActionEvent event )
{
// clear the JTextFields
inputJTextField2.setText( "" );
displayJTextArea.setText("");

} // end method clearJButtonActionPerformed

private void enterJButtonActionPerformed( ActionEvent event )
{
double z;
double c;
int x;
int y;
x=selectCountryJComboBox.getSelectedIndex();
y=Integer.parseInt(inputJTextField2.getText());
double discountRate;
int amount = Integer.parseInt( inputJTextField2.getText());
switch (amount/5)
{
case 0:
discountRate = 0;
break;

case 1:
discountRate = 1;
break;

case 2:
discountRate = 2;
break;
case 3:
discountRate = 3;
break;

default:
discountRate = 4;

} // end switch statement
c=1-discountRate/100;
z=jiage[x]*y*c;
displayJTextArea.append("你選擇的是:"+cars[x]+";"+
"它的單價是:"+jiage[x]+";" +"你購買該產品的數量是:"+y+"," +"\n"+"該數量的折扣是:"
+discountRate + " %"+";"+"本次消費的總價格是:"+z+"元"+"!"+"\n");

}
public static void main( String args[] )
{
carshop application = new carshop();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

} // end method main

} // end class carshop

『叄』 Java100行以上源代碼,至少五個class以及一個interface,可以簡單點

下面是一個可能的Java源代碼,它包含了一個介面租沖薯(Shape)和五個類(Circle, Rectangle, Triangle, Square 和 Main)。它的功能是計算不同形狀的面積和周長。
//定義一個介面Shape,有兩判指個抽象方法:getArea()和getPerimeter()interface Shape { double getArea(); double getPerimeter();
}//定義一個類Circle,實現Shape介面class Circle implements Shape { //定義一個私有屬性radius,表示圓的半徑
private double radius; //定義一個公有構造方法,用於初始化radius
public Circle(double radius) { this.radius = radius;
} //實現getArea()方法,返回圓的面積
public double getArea() { return Math.PI * radius * radius;
} //實現getPerimeter()方法,返回圓的周長
public double getPerimeter() { return Math.PI * radius * 2;
}
}//定義一個類Rectangle,實現Shape介面class Rectangle implements Shape { //定義兩個私有屬性width和height,表示矩形的寬度和高度
private double width; private double height; //定義一個公有構造方法,用於初始化width和height
public Rectangle(double width, double height) { this.width = width; this.height = height;
} //實現getArea()方法,返回矩形的面積
public double getArea() { return width * height;
} //實現getPerimeter()方法,返回矩形的周長
public double getPerimeter() { return (width + height) *2;
}
}//定義一個類Triangle,實現Shape介面class Triangle implements Shape { //定義三個私有屬性a,b,c表示三角形的三條邊長
private double a; private double b; private double c; //定義一個公有構造方法,用於初始化a,b,c,並檢查是否滿足三角形條件(任意兩邊之和大於第三邊)
public Triangle(double a, double b, double c) throws Exception{ if (a + b > c && a + c > b && b + c > a) {
this.a = a; this.b = b;
this.c = c;
} else {
throw new Exception("Invalid triangle");
}
} //實現getArea()方法,返回三角形的面積(使用海倫公式)
public double getArea() { //計算半周長p
double p = (a + b + c) /2; //計算並返回面積s(使用Math.sqrt()函數求平方根)
return Math.sqrt(p * (p - a) * (p - b) * (p - c));
} //實現getPerimeter()方法,返回三角形的周長
public double getPerimeter(){ return a + b + c;
}
}//定義一個類Square,繼承Rectangle類,並重寫構造方法和toString()方法class Square extends Rectangle { //重寫構造方法,在調用父類構造方法時傳入相弊者同的參數side作為width和height
public Square(double side){ super(side, side);
} //重寫toString()方法,在原來基礎上加上"Square:"前綴,並只顯示side屬性而不顯示width和height屬性(使用String.format()函數格式化字元串)
@Override
public String toString(){ return String.format("Square: side=%.2f", super.width); /* 或者直接使用super.getPerimeter()/4作為side */
/* return String.format("Square: side=%.2f", super.getPerimeter()/4); */

/* 注意:不能直接訪問super.side屬性,

『肆』 如何查看JDK源碼

在Eclipse中查看JDK類庫的源代碼方法設置:
1.點 「window」-> "Preferences" -> "Java" -> "Installed JRES";
2.此時"Installed JRES"右邊是列表窗格,列出了系統中的 JRE 環境,選擇JRE,然後點邊上的 "Edit...", 會出現一個窗口(Edit JRE);
3.選中rt.jar文件的這一項:「c:\program files\java\jre_1.5.0_06\lib\rt.jar」
點 左邊的「+」 號展開它;
4.展開後,可以看到「Source Attachment:(none)」,點這一項,點右邊的按鈕「Source Attachment...」, 選擇JDK目錄下的 「src.zip」文件;
5.一路點"ok",結束。

dt.jar是關於運行環境的類庫,主要是swing的包
tools.jar是關於一些工具的類庫
rt.jar包含了jdk的基礎類庫,也就是在java doc裡面看到的所有的類的class文件

使用方法:
可以在 Java 源代碼編輯器或代碼片段編輯測試窗中選擇類型、方法或欄位的名稱,然後對元素的定義打開編輯器。
在 Java 編輯器中,選擇類型、方法或欄位的名稱。也可以僅僅在名稱中單擊一次。
執行下列其中一項操作:
1.從菜單欄中,選擇瀏覽 > 打開聲明;
2.從編輯器的彈出菜單中,選擇打開聲明;
3.按 F3鍵,遷移到一個class文件拿去;
4、class文件畫面會有一個「關聯源代碼」按鈕,點擊這個按鈕,然後從系統文件選擇jdk下的src.zip文件。
這樣就可以直接看到源碼了。

『伍』 JAVA寵物商店的源代碼 系統啟動和寵物主人登錄的介面具體代碼是什麼

publicinterface介面A{

publicvoidget();

}

//**************

publicclass介面A的實現類implements介面A{

@Override
publicvoidget(){

System.out.println(1);

}

}
//**************

publicclassTest{

介面Ad=new介面A的實現類();

publicTest(){
d.get();

}

}

雖然可以,但不提倡,因為介面有其自己的存在意義,介面定義行為,一般的都是介面定義,然後用一個類實現。
如果您必須要在介面中實現方法:
publicinterface介面A{

publicvoidget();

publicdefaultvoidset(){
//實現
}

}

『陸』 跪求一個小型超市管理系統,用java編寫的,急~ 只要源代碼。。可以發我郵箱

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Conn {
private static final String driver="com.mysql.jdbc.Driver";
private static final String url="jdbc:mysql://localhost:3306/blog?user=root&password=root";

//獲得資料庫連接
public static Connection getConnection(){
Connection conn = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(url);
if(conn != null){
System.out.print("成功");
}
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return conn;

}

//關閉Resultset
public static void closeResultSet(ResultSet rs)
{
try
{
if(rs != null)
{
rs.close();
}
}catch (SQLException ex)
{
ex.printStackTrace();
}
}

//關閉Statement
public static void closeStatement(Statement st)
{
try
{
if(st != null)
{
st.close();
}
}catch (SQLException ex)
{
ex.printStackTrace();
}
}

//關閉Connection
public static void closeConnection(Connection conn)
{
try
{
if(conn != null)
{
conn.close();
}
}catch (SQLException ex)
{
ex.printStackTrace();
}
}

//測試資料庫連接是否成功
public static void main(String[] args) {
Conn.getConnection();
}

}

閱讀全文

與java物聯源碼相關的資料

熱點內容
海綿寶寶大電影免費中文版 瀏覽:275
愛國戰爭片免費觀看 瀏覽:887
三位數碼管單片機是如何工作的 瀏覽:728
免費看不下載老電影院 瀏覽:511
啄木鳥影業都有哪些作品 瀏覽:824
在電腦上怎麼把pdf保存成圖片 瀏覽:767
末段愛情廣播劇是哪個app可以聽 瀏覽:322
e片免費看 瀏覽:361
成龍教外國小孩功夫電影叫什麼 瀏覽:482
disk命令分區 瀏覽:912
丁巴度愛與激情 瀏覽:264
韓國野戰電影 瀏覽:462
法國chouchou在線觀看 瀏覽:700
linux歷史命令查看 瀏覽:964
堅果安卓11怎麼樣 瀏覽:497
imovie壓縮 瀏覽:453
古裝鬼電影大全 瀏覽:457
韓電影app 瀏覽:888
何炅參加密室逃脫視頻 瀏覽:897
日本生孩子電影 瀏覽:262