需要將jar包和源代碼關(guān)聯(lián),步驟如下:
創(chuàng)新互聯(lián)主營揚州網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶APP開發(fā),揚州h5重慶小程序開發(fā)搭建,揚州網(wǎng)站營銷推廣歡迎揚州等地區(qū)企業(yè)咨詢
點 “window”- "Preferences" - "Java" - "Installed JRES"
2.此時"Installed JRES"右邊是列表窗格,列出了系統(tǒng)中的 JRE 環(huán)境,選擇你的JRE,然后點邊上的 "Edit", 會出現(xiàn)一個窗口(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",結(jié)束。
public class Invoice {
String bianhao = null;
String shuoming = null;
int count = 0;
double price = 0.0;
public Invoice(String bianhao, String shuoming, int count, double price) {
this.bianhao = bianhao;
this.shuoming = shuoming;
if (count 0) {
this.count = 0;
} else {
this.count = count;
}
if (price 0.0) {
this.price = 0.0;
} else {
this.price = price;
}
}
public double getInvoiceAmount() {
return count * price;
}
public String getBianhao() {
return bianhao;
}
public void setBianhao(String bianhao) {
this.bianhao = bianhao;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getShuoming() {
return shuoming;
}
public void setShuoming(String shuoming) {
this.shuoming = shuoming;
}
}
public class InvoiceTest {
/**
* @param args
*/
public static void main(String[] args) {
Invoice invoice = new Invoice("010220", "Desk", 50, 53.9);
System.out.println(invoice.getInvoiceAmount());
}
}
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.awt.datatransfer.*;
class MyMenuBar extends MenuBar{
public MyMenuBar(Frame parent){
parent.setMenuBar(this);
}
public void addMenus(String [] menus){
for(int i=0;imenus.length;i++)
add(new Menu(menus[i]));
}
public void addMenuItems(int menuNumber,String[] items){
for(int i=0;iitems.length;i++){
if(items[i]!=null)
getMenu(menuNumber).add(new MenuItem(items[i]));
else getMenu(menuNumber).addSeparator();
}
}
public void addActionListener(ActionListener al){
for(int i=0;igetMenuCount();i++)
for(int j=0;jgetMenu(i).getItemCount();j++)
getMenu(i).getItem(j).addActionListener(al);
}
}
class MyFile{
private FileDialog fDlg;
public MyFile(Frame parent){
fDlg=new FileDialog(parent,"",FileDialog.LOAD);
}
private String getPath(){
return fDlg.getDirectory()+"\\"+fDlg.getFile();
}
public String getData() throws IOException{
fDlg.setTitle("打開");
fDlg.setMode(FileDialog.LOAD);
fDlg.setVisible(true);
BufferedReader br=new BufferedReader(new FileReader(getPath()));
StringBuffer sb=new StringBuffer();
String aline;
while((aline=br.readLine())!=null)
sb.append(aline+'\n');
br.close();
return sb.toString();
}
public void setData(String data) throws IOException{
fDlg.setTitle("保存");
fDlg.setMode(FileDialog.SAVE);
fDlg.setVisible(true);
BufferedWriter bw=new BufferedWriter(new FileWriter(getPath()));
bw.write(data);
bw.close();
}
}
class MyClipboard{
private Clipboard cb;
public MyClipboard(){
cb=Toolkit.getDefaultToolkit().getSystemClipboard();
}
public void setData(String data){
cb.setContents(new StringSelection(data),null);
}
public String getData(){
Transferable content=cb.getContents(null);
try{
return (String) content.getTransferData(DataFlavor.stringFlavor);
//DataFlavor.stringFlavor會將剪貼板中的字符串轉(zhuǎn)換成Unicode碼形式的String對象。
//DataFlavor類是與存儲在剪貼板上的數(shù)據(jù)的形式有關(guān)的類。
}catch(Exception ue){}
return null;
}
}
class MyFindDialog extends Dialog implements ActionListener{
private Label lFind=new Label("查找字符串");
private Label lReplace=new Label("替換字符串");
private TextField tFind=new TextField(10);
private TextField tReplace=new TextField(10);
private Button bFind=new Button("查找");
private Button bReplace=new Button("替換");
private TextArea ta;
public MyFindDialog(Frame owner,TextArea ta){
super(owner,"查找",false);
this.ta=ta;
setLayout(null);
lFind.setBounds(10,30,80,20);
lReplace.setBounds(10,70,80,20);
tFind.setBounds(90,30,90,20);
tReplace.setBounds(90,70,90,20);
bFind.setBounds(190,30,80,20);
bReplace.setBounds(190,70,80,20);
add(lFind);
add(tFind);
add(bFind);
add(lReplace);
add(tReplace);
add(bReplace);
setResizable(false);
bFind.addActionListener(this);
bReplace.addActionListener(this);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
MyFindDialog.this.dispose();
}
});
}//構(gòu)造函數(shù)結(jié)束
public void showFind(){
setTitle("查找");
setSize(280,60);
setVisible(true);
}
public void showReplace(){
setTitle("查找替換");
setSize(280,110);
setVisible(true);
}
private void find(){
String text=ta.getText();
String str=tFind.getText();
int end=text.length();
int len=str.length();
int start=ta.getSelectionEnd();
if(start==end) start=0;
for(;start=end-len;start++){
if(text.substring(start,start+len).equals(str)){
ta.setSelectionStart(start);
ta.setSelectionEnd(start+len);
return;
}
}
//若找不到待查字符串,則將光標置于末尾
ta.setSelectionStart(end);
ta.setSelectionEnd(end);
}
public Button getBFind() {
return bFind;
}
private void replace(){
String str=tReplace.getText();
if(ta.getSelectedText().equals(tFind.getText()))
ta.replaceRange(str,ta.getSelectionStart(),ta.getSelectionEnd());
else find();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==bFind)
find();
else if(e.getSource()==bReplace)
replace();
}
}
public class MyMemo extends Frame implements ActionListener{
private TextArea editor=new TextArea(); //可編輯的TextArea
private MyFile mf=new MyFile(this);//MyFile對象
private MyClipboard cb=new MyClipboard();
private MyFindDialog findDlg=new MyFindDialog(this,editor);
public MyMemo(String title){ //構(gòu)造函數(shù)
super(title);
MyMenuBar mb=new MyMenuBar(this);
//添加需要的菜單及菜單項
mb.addMenus(new String[]{"文件","編輯","查找","幫助"});
mb.addMenuItems(0,new String[]{"新建","打開","保存",null,"全選"});
mb.addMenuItems(1,new String[]{"剪貼","復(fù)制","粘貼","清除",null,"全選"});
mb.addMenuItems(2,new String[]{"查找",null,"查找替換"});
mb.addMenuItems(3,new String[]{"我的記事本信息"});
add(editor); //為菜單項注冊動作時間監(jiān)聽器
mb.addActionListener(this);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
MyMemo.this.dispose();
}
}); //分號不能忘了
} //構(gòu)造函數(shù)完
public void actionPerformed(ActionEvent e){
String selected=e.getActionCommand(); //獲取菜單項標題
if(selected.equals("新建"))
editor.setText("");
else if(selected.equals("打開")){
try{
editor.setText(mf.getData());
}catch(IOException ie){}
}
else if(selected.equals("保存")){
try{
mf.setData(editor.getText());
}catch(IOException ie){}
}
else if(selected.equals("退出")){
dispose();
}
else if(selected.equals("剪貼")){
//將選中的字符串復(fù)制到剪貼板中并清除字符串
cb.setData(editor.getSelectedText());
editor.replaceRange("",editor.getSelectionStart(),editor.getSelectionEnd());
}
else if(selected.equals("復(fù)制")){
cb.setData(editor.getSelectedText());
}
else if(selected.equals("粘貼")){
String str=cb.getData();
editor.replaceRange(str,editor.getSelectionStart(),editor.getSelectionEnd());
//粘貼在光標位置
}
else if(selected.equals("清除")){
editor.replaceRange("",editor.getSelectionStart(),editor.getSelectionEnd());
}
else if(selected.equals("全選")){
editor.setSelectionStart(0);
editor.setSelectionEnd(editor.getText().length());
}
else if(selected.equals("查找")){
findDlg.showFind();
}
else if(selected.equals("查找替換")){
findDlg.showReplace();
}
}
public static void main(String[] args){
MyMemo memo=new MyMemo("記事本");
memo.setSize(650,450);
memo.setVisible(true);
}
}
//參考下吧
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.print.*;
import java.util.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.swing.*;
/**
This program demonstrates how to print 2D graphics
*/
public class PrintTest
{
public static void main(String[] args)
{
JFrame frame = new PrintTestFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
/**
This frame shows a panel with 2D graphics and buttons
to print the graphics and to set up the page format.
*/
class PrintTestFrame extends JFrame
{
public PrintTestFrame()
{
setTitle("PrintTest");
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
canvas = new PrintPanel();
add(canvas, BorderLayout.CENTER);
attributes = new HashPrintRequestAttributeSet();
JPanel buttonPanel = new JPanel();
JButton printButton = new JButton("Print");
buttonPanel.add(printButton);
printButton.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
try
{
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(canvas);
if (job.printDialog(attributes))
job.print(attributes);
}
catch (PrinterException e)
{
JOptionPane.showMessageDialog(PrintTestFrame.this, e);
}
}
});
JButton pageSetupButton = new JButton("Page setup");
buttonPanel.add(pageSetupButton);
pageSetupButton.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
PrinterJob job = PrinterJob.getPrinterJob();
job.pageDialog(attributes);
}
});
add(buttonPanel, BorderLayout.NORTH);
}
private PrintPanel canvas;
private PrintRequestAttributeSet attributes;
private static final int DEFAULT_WIDTH = 300;
private static final int DEFAULT_HEIGHT = 300;
}
/**
This panel generates a 2D graphics image for screen display
and printing.
*/
class PrintPanel extends JPanel implements Printable
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
drawPage(g2);
}
public int print(Graphics g, PageFormat pf, int page)
throws PrinterException
{
if (page = 1) return Printable.NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D) g;
g2.translate(pf.getImageableX(), pf.getImageableY());
g2.draw(new Rectangle2D.Double(0, 0, pf.getImageableWidth(), pf.getImageableHeight()));
drawPage(g2);
return Printable.PAGE_EXISTS;
}
/**
This method draws the page both on the screen and the
printer graphics context.
@param g2 the graphics context
*/
public void drawPage(Graphics2D g2)
{
FontRenderContext context = g2.getFontRenderContext();
Font f = new Font("Serif", Font.PLAIN, 72);
GeneralPath clipShape = new GeneralPath();
TextLayout layout = new TextLayout("Hello", f, context);
AffineTransform transform = AffineTransform.getTranslateInstance(0, 72);
Shape outline = layout.getOutline(transform);
clipShape.append(outline, false);
layout = new TextLayout("World", f, context);
transform = AffineTransform.getTranslateInstance(0, 144);
outline = layout.getOutline(transform);
clipShape.append(outline, false);
g2.draw(clipShape);
g2.clip(clipShape);
final int NLINES =50;
Point2D p = new Point2D.Double(0, 0);
for (int i = 0; i NLINES; i++)
{
double x = (2 * getWidth() * i) / NLINES;
double y = (2 * getHeight() * (NLINES - 1 - i))
/ NLINES;
Point2D q = new Point2D.Double(x, y);
g2.draw(new Line2D.Double(p, q));
}
}
}
class People {
public void sayHello(){}
}
class Student extends People{
public void sayHello(){......}
}
class Teacher extends People{
public void sayHello{......}
}
.
.
.
.
public Text {
public static void main(String [] str){
People p1 = new Student();
p2 = new Teacher();
p1.sayHello();
p2.sayHello();
}
}
不知是不是您要的答案,如果您正在學(xué)習(xí)Java,這個應(yīng)該屬于基本常識吧??
BS 架構(gòu)很好做??!就是單表 select \ insert update delete 操作, 這個功能很好寫的,你說的這些代碼,有些還可以用工具生成