189 8069 5689

经典java源代码 java经典程序代码

哪些Java 源代码看了后收获很多代码思维有较大的提升

需要将jar包和源代码关联,步骤如下:

创新互联主营扬州网站建设的网络公司,主营网站建设方案,重庆APP开发,扬州h5重庆小程序开发搭建,扬州网站营销推广欢迎扬州等地区企业咨询

点 “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",结束。

一道Java编程题 求源代码

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());

}

}

求一个用JAVA写的简单的记事本源代码程序

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会将剪贴板中的字符串转换成Unicode码形式的String对象。

//DataFlavor类是与存储在剪贴板上的数据的形式有关的类。

}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();

}

});

}//构造函数结束

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){ //构造函数

super(title);

MyMenuBar mb=new MyMenuBar(this);

//添加需要的菜单及菜单项

mb.addMenus(new String[]{"文件","编辑","查找","帮助"});

mb.addMenuItems(0,new String[]{"新建","打开","保存",null,"全选"});

mb.addMenuItems(1,new String[]{"剪贴","复制","粘贴","清除",null,"全选"});

mb.addMenuItems(2,new String[]{"查找",null,"查找替换"});

mb.addMenuItems(3,new String[]{"我的记事本信息"});

add(editor); //为菜单项注册动作时间监听器

mb.addActionListener(this);

addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent e){

MyMemo.this.dispose();

}

}); //分号不能忘了

} //构造函数完

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("剪贴")){

//将选中的字符串复制到剪贴板中并清除字符串

cb.setData(editor.getSelectedText());

editor.replaceRange("",editor.getSelectionStart(),editor.getSelectionEnd());

}

else if(selected.equals("复制")){

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);

}

}

谁有java打印的源代码

//参考下吧

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));

}

}

}

编写一个java程序的源代码

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();

}

}

不知是不是您要的答案,如果您正在学习Java,这个应该属于基本常识吧??

求java源代码

BS 架构很好做啊!就是单表 select \ insert update delete 操作, 这个功能很好写的,你说的这些代码,有些还可以用工具生成


网页名称:经典java源代码 java经典程序代码
网站网址:http://cdxtjz.com/article/hhpdjg.html

其他资讯