天啊,?冖_Na0?為什么會有我編的記事本代碼呢???呵呵……你肯定是“請教”過我的吧??
成都創(chuàng)新互聯(lián)公司為企業(yè)級客戶提高一站式互聯(lián)網(wǎng)+設(shè)計(jì)服務(wù),主要包括網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站建設(shè)、成都app軟件開發(fā)、重慶小程序開發(fā)公司、宣傳片制作、LOGO設(shè)計(jì)等,幫助客戶快速提升營銷能力和企業(yè)形象,創(chuàng)新互聯(lián)各部門都有經(jīng)驗(yàn)豐富的經(jīng)驗(yàn),可以確保每一個作品的質(zhì)量和創(chuàng)作周期,同時每年都有很多新員工加入,為我們帶來大量新的創(chuàng)意。
呵呵……我自己編了一個,不過呢,沒有windows那么多的功能啊。
涉及到兩個文件:
第一個文件中的代碼:
package?MyProject;
import?java.awt.BorderLayout;
import?javax.swing.JPanel;
import?javax.swing.JFrame;
import?java.awt.Dimension;
import?javax.swing.JMenuBar;
import?javax.swing.JMenu;
import?javax.swing.JMenuItem;
import?javax.swing.JLabel;
import?java.awt.Rectangle;
import?javax.swing.JTextArea;
import?javax.swing.JScrollPane;
import?java.awt.datatransfer.*;
import?java.io.*;
public?class?MainFrame?extends?JFrame?{
private?static?final?long?serialVersionUID?=?1L;
private?JPanel?jContentPane?=?null;
private?JMenuBar?jJMenuBar?=?null;
private?JMenu?jMenu?=?null;
private?JMenu?jMenu1?=?null;
private?JMenu?jMenu2?=?null;
private?JMenuItem?jMenuItem?=?null;
private?JMenuItem?jMenuItem1?=?null;
private?JMenuItem?jMenuItem2?=?null;
private?JMenuItem?jMenuItem3?=?null;
private?JLabel?jLabel?=?null;
private?JScrollPane?jScrollPane?=?null;
private?JTextArea?jTextArea?=?null;
private?JMenuItem?jMenuItem4?=?null;
private?JMenuItem?jMenuItem5?=?null;
private?JMenuItem?jMenuItem6?=?null;
private?JMenuItem?jMenuItem7?=?null;
private?static?MainFrame?myMainFrame=null;
private?static?String?textstr="";///用于記錄文本文件的路徑
private?File?myFile=null;
private?FileReader?myrder=null;
private?FileWriter?mywr=null;
/**
*?This?is?the?default?constructor
*/
public?MainFrame()?{
super();
initialize();
}
/**
*?This?method?initializes?this
*
*?@return?void
*/
private?void?initialize()?{
this.setSize(412,?350);
this.setJMenuBar(getJJMenuBar());
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
this.addWindowListener(new?java.awt.event.WindowAdapter()?{
public?void?windowActivated(java.awt.event.WindowEvent?e)?{
if(!textstr.equals("")){
try{
myFile=new?File(textstr);
if(!myFile.exists()){
myFile.createNewFile();
}
myrder=new?FileReader(myFile);
char[]?mychar=new?char[(int)myFile.length()];
myrder.read(mychar);
String?tmp=new?String(mychar);
jTextArea.setText(tmp);
myrder.close();
}
catch(Exception?ee){
ee.printStackTrace();
}
}
}
public?void?windowClosing(java.awt.event.WindowEvent?e)?{
System.exit(0);
}
});
this.setVisible(true);
myMainFrame=this;
}
/**
*?This?method?initializes?jContentPane
*
*?@return?javax.swing.JPanel
*/
private?JPanel?getJContentPane()?{
if?(jContentPane?==?null)?{
jLabel?=?new?JLabel();
jLabel.setBounds(new?Rectangle(15,?18,?65,?18));
jLabel.setText("文件內(nèi)容:");
jContentPane?=?new?JPanel();
jContentPane.setLayout(null);
jContentPane.add(jLabel,?null);
jContentPane.add(getJScrollPane(),?null);
}
return?jContentPane;
}
/**
*?This?method?initializes?jJMenuBar
*
*?@return?javax.swing.JMenuBar
*/
private?JMenuBar?getJJMenuBar()?{
if?(jJMenuBar?==?null)?{
jJMenuBar?=?new?JMenuBar();
jJMenuBar.add(getJMenu());
jJMenuBar.add(getJMenu1());
jJMenuBar.add(getJMenu2());
}
return?jJMenuBar;
}
/**
*?This?method?initializes?jMenu
*
*?@return?javax.swing.JMenu
*/
private?JMenu?getJMenu()?{
if?(jMenu?==?null)?{
jMenu?=?new?JMenu();
jMenu.setText("文件");
jMenu.add(getJMenuItem());
jMenu.add(getJMenuItem1());
jMenu.add(getJMenuItem2());
jMenu.add(getJMenuItem3());
}
return?jMenu;
}
/**
*?This?method?initializes?jMenu1
*
*?@return?javax.swing.JMenu
*/
private?JMenu?getJMenu1()?{
if?(jMenu1?==?null)?{
jMenu1?=?new?JMenu();
jMenu1.setText("編輯");
jMenu1.add(getJMenuItem4());
jMenu1.add(getJMenuItem5());
jMenu1.add(getJMenuItem6());
}
return?jMenu1;
}
/**
*?This?method?initializes?jMenu2
*
*?@return?javax.swing.JMenu
*/
private?JMenu?getJMenu2()?{
if?(jMenu2?==?null)?{
jMenu2?=?new?JMenu();
jMenu2.setText("幫助");
jMenu2.add(getJMenuItem7());
}
return?jMenu2;
}
/**
*?This?method?initializes?jMenuItem
*
*?@return?javax.swing.JMenuItem
*/
private?JMenuItem?getJMenuItem()?{
if?(jMenuItem?==?null)?{
jMenuItem?=?new?JMenuItem();
jMenuItem.setText("打開");
jMenuItem.addActionListener(new?java.awt.event.ActionListener()?{
public?void?actionPerformed(java.awt.event.ActionEvent?e)?{
MainFrame.this.myMainFrame.setEnabled(false);
SelectTextFile?mysl=new?SelectTextFile();
mysl.setVisible(true);
}
});
}
return?jMenuItem;
}
/**
*?This?method?initializes?jMenuItem1
*
*?@return?javax.swing.JMenuItem
*/
private?JMenuItem?getJMenuItem1()?{
if?(jMenuItem1?==?null)?{
jMenuItem1?=?new?JMenuItem();
jMenuItem1.setText("關(guān)閉");
jMenuItem1.addActionListener(new?java.awt.event.ActionListener()?{
public?void?actionPerformed(java.awt.event.ActionEvent?e)?{
try{
myFile=null;
}
catch(Exception?ee){
ee.printStackTrace();
}
jTextArea.setText("");
}
});
}
return?jMenuItem1;
}
/**
*?This?method?initializes?jMenuItem2
*
*?@return?javax.swing.JMenuItem
*/
private?JMenuItem?getJMenuItem2()?{
if?(jMenuItem2?==?null)?{
jMenuItem2?=?new?JMenuItem();
jMenuItem2.setText("保存");
jMenuItem2.addActionListener(new?java.awt.event.ActionListener()?{
public?void?actionPerformed(java.awt.event.ActionEvent?e)?{
try{
String?tmp=jTextArea.getText();
char[]?mychar=tmp.toCharArray();
myFile.delete();
myFile.createNewFile();
mywr=new?FileWriter(myFile);
mywr.write(mychar);
mywr.close();
}
catch(Exception?ee){
ee.printStackTrace();
}
}
});
}
return?jMenuItem2;
}
/**
*?This?method?initializes?jMenuItem3
*
*?@return?javax.swing.JMenuItem
*/
private?JMenuItem?getJMenuItem3()?{
if?(jMenuItem3?==?null)?{
jMenuItem3?=?new?JMenuItem();
jMenuItem3.setText("退出");
jMenuItem3.addActionListener(new?java.awt.event.ActionListener()?{
public?void?actionPerformed(java.awt.event.ActionEvent?e)?{
System.exit(0);
}
});
}
return?jMenuItem3;
}
/**
*?This?method?initializes?jScrollPane
*
*?@return?javax.swing.JScrollPane
*/
private?JScrollPane?getJScrollPane()?{
if?(jScrollPane?==?null)?{
jScrollPane?=?new?JScrollPane();
jScrollPane.setBounds(new?Rectangle(15,?46,?371,?225));
jScrollPane.setViewportView(getJTextArea());
}
return?jScrollPane;
}
/**
*?This?method?initializes?jTextArea
*
*?@return?javax.swing.JTextArea
*/
private?JTextArea?getJTextArea()?{
if?(jTextArea?==?null)?{
jTextArea?=?new?JTextArea();
}
return?jTextArea;
}
/**
*?This?method?initializes?jMenuItem4
*
*?@return?javax.swing.JMenuItem
*/
private?JMenuItem?getJMenuItem4()?{
if?(jMenuItem4?==?null)?{
jMenuItem4?=?new?JMenuItem();
jMenuItem4.setText("復(fù)制");
jMenuItem4.addActionListener(new?java.awt.event.ActionListener()?{
public?void?actionPerformed(java.awt.event.ActionEvent?e)?{
MainFrame.this.setClipboardText(MainFrame.this.getToolkit().getSystemClipboard(),jTextArea.getSelectedText());
}
});
}
return?jMenuItem4;
}
/**
*?This?method?initializes?jMenuItem5
*
*?@return?javax.swing.JMenuItem
*/
private?JMenuItem?getJMenuItem5()?{
if?(jMenuItem5?==?null)?{
jMenuItem5?=?new?JMenuItem();
jMenuItem5.setText("剪切");
jMenuItem5.addActionListener(new?java.awt.event.ActionListener()?{
public?void?actionPerformed(java.awt.event.ActionEvent?e)?{
MainFrame.this.setClipboardText(MainFrame.this.getToolkit().getSystemClipboard(),jTextArea.getSelectedText());
jTextArea.setText(jTextArea.getText().substring(0,jTextArea.getSelectionStart()));
}
});
}
return?jMenuItem5;
}
/**
*?This?method?initializes?jMenuItem6
*
*?@return?javax.swing.JMenuItem
*/
private?JMenuItem?getJMenuItem6()?{
if?(jMenuItem6?==?null)?{
jMenuItem6?=?new?JMenuItem();
jMenuItem6.setText("黏貼");
jMenuItem6.addActionListener(new?java.awt.event.ActionListener()?{
public?void?actionPerformed(java.awt.event.ActionEvent?e)?{
try{
jTextArea.setText(jTextArea.getText().substring(0,jTextArea.getSelectionStart()));
jTextArea.setText(jTextArea.getText()+(MainFrame.this.getClipboardText(MainFrame.this.getToolkit().getSystemClipboard())));
}
catch(Exception?ee){
ee.printStackTrace();
}
}
});
}
return?jMenuItem6;
}
/**
*?This?method?initializes?jMenuItem7
*
*?@return?javax.swing.JMenuItem
*/
private?JMenuItem?getJMenuItem7()?{
if?(jMenuItem7?==?null)?{
jMenuItem7?=?new?JMenuItem();
jMenuItem7.setText("關(guān)于記事本");
jMenuItem7.addActionListener(new?java.awt.event.ActionListener()?{
public?void?actionPerformed(java.awt.event.ActionEvent?e)?{
////暫無代碼?。?/p>
}
});
}
return?jMenuItem7;
}
public?static?void?main(String?args[]){
new?MainFrame();
}
public?static?MainFrame?getMyMainFrame()?{
return?myMainFrame;
}
public?static?void?setMyMainFrame(MainFrame?myMainFrame)?{
MainFrame.myMainFrame?=?myMainFrame;
}
public?static?String?getTextstr()?{
return?textstr;
}
public?static?void?setTextstr(String?textstr)?{
MainFrame.textstr?=?textstr;
}
protected?static?String?getClipboardText(Clipboard?clip)?throws?Exception{
Transferable?clipT?=?clip.getContents(null);//?獲取剪切板中的內(nèi)容
if?(clipT?!=?null)?{
if?(clipT.isDataFlavorSupported(DataFlavor.stringFlavor))?//?檢查內(nèi)容是否是文本類型
return?(String)clipT.getTransferData(DataFlavor.stringFlavor);
}
return?null;
}
protected?static?void?setClipboardText(Clipboard?clip,?String?writeMe)?{
Transferable?tText?=?new?StringSelection(writeMe);
clip.setContents(tText,?null);
}
}??//??@jve:decl-index=0:visual-constraint="10,10"
第二個文件中的代碼:
(太長了,貼不上來)
整個效果就是實(shí)現(xiàn)了基本的打開、關(guān)閉、保存、退出的功能。
效果如圖:
package threadgroup;
class ThreadDemo3 extends Thread {
private String name;
private int delay;
public ThreadDemo3(String sname, int i_delay) {
name = sname;
delay = i_delay;
}
public void run() {
try {
sleep(delay);
} catch (InterruptedException e) {
}
System.out.println("多線程測試!\n" + name + "\n" + delay);
}
}
public class testMyThread {
public static void main(String[] args) {
ThreadDemo3 th1,th2,th3;
th1 = new ThreadDemo3("線程1", (int) (Math.random() * 900));
th2 = new ThreadDemo3("線程2", (int) (Math.random() * 900));
th3 = new ThreadDemo3("線程3", (int) (Math.random() * 900));
th1.start();
th2.start();
th3.start();
}
}
package threadgroup;
public class threadDemo {
public static void main(String[] args) {
Thread t = Thread.currentThread();
t.setName("你好嗎?");
System.out.println("正在進(jìn)行的Thread是:" + t);
try {
for (int i = 0; i 5; i++) {
System.out.println("我不叫穆繼超" + i);
Thread.sleep(3000);
}
} catch (Exception e) {
// TODO: handle exception
System.out.println("Thread has wrong" + e.getMessage());
}
}
}
package threadgroup;
public class threadDemo2 implements Runnable {
public threadDemo2() {
Thread t1 = Thread.currentThread();
t1.setName("第一個主進(jìn)程");
System.out.println("正在運(yùn)行" + t1);
Thread t2 = new Thread(this, "");
System.out.println("在創(chuàng)建一個進(jìn)程");
t2.start();
try {
System.out.println("使他進(jìn)入第一個睡眠狀態(tài)");
Thread.sleep(2000);
} catch (InterruptedException e) {
System.out.println("Thread has wrong" + e.getMessage());
}
System.out.println("退出第一個進(jìn)程");
}
public void run() {
try {
for (int i = 0; i 5; i++) {
System.out.println("進(jìn)程" + i);
Thread.sleep(3000);
}
} catch (InterruptedException e) {
// TODO: handle exception
System.out.println("Thread has wrong" + e.getMessage());
}
System.out.println("退出第二個進(jìn)程");
}
public static void main(String[] args) {
new threadDemo2();
}
}
import java.util.Scanner;
public class colPrice{
public static void main(String[] args){
double[] price = new double[10];
double totalPrice = 0;
System.out.println("請輸入商品價格:");
for(int i=0;i10;i++){
System.out.print(i+1+": ");
Scanner in = new Scanner( System.in);
price[i] = in.nextDouble();
}
System.out.println("");
for(int i= 0;iprice.length;i++){
totalPrice+=price[i];
}
System.out.println("商品總價格是:"+totalPrice);
}
}
1、Eclipse - IBM甩出來給開源社區(qū)的IDE,其本身就是使用Java開發(fā)的。\x0d\x0a2、MyEclipse - 把Eclipse包裝了一下,加了J2EE企業(yè)開發(fā)的許多功能強(qiáng)大的插件。\x0d\x0a3、NetBeans - SUN公司自己開發(fā)的Java開發(fā)環(huán)境,功能挺多的。\x0d\x0a4、還有一些超喜歡手工編寫Java代碼的牛人喜歡使用帶語法著色功能的純文本編輯器編寫Java程序,代碼寫完后在命令提示符下編譯運(yùn)行。這種方式只適用寫少量代碼或作為學(xué)習(xí)使用,開發(fā)大型項(xiàng)目不適用,因?yàn)樾屎艿汀?/p>
網(wǎng)頁題目:推薦代碼java,推薦代碼GB
URL標(biāo)題:http://weahome.cn/article/dsiiihs.html