java简单记事本代码

简单记事本的java程序代码~

天啊, 冖_Na0 为什么会有我编的记事本代码呢???呵呵……你肯定是“请教”过我的吧??
呵呵……我自己编了一个,不过呢,没有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("文件内容:");
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("关闭");
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("复制");
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("关于记事本");
jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
////暂无代码!!
}
});
}
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);// 获取剪切板中的内容
if (clipT != null) {
if (clipT.isDataFlavorSupported(DataFlavor.stringFlavor)) // 检查内容是否是文本类型
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"
第二个文件中的代码:
(太长了,贴不上来)
整个效果就是实现了基本的打开、关闭、保存、退出的功能。
效果如图:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
class test implements ActionListener
{
JFrame frame;
JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,b30,b31;
JTextArea ta;
JPanel p1,p2,p3,p4;
JMenuBar mb;
JMenu m1,m2,m3;
JMenuItem mt1,mt2,mt3,mt4,mt5,mt6,mt7;
JRadioButton rb1,rb2;
ButtonGroup bg;
Double d1=0.0,d2=0.0,d3=0.0,d4=1.0,d5=1.0;
String s1="",s2="",s3="",s4="";
int a=0;
char c1;
int i=0;
public static void main(String[] args)
{
test that=new test();
that.go();

}
public void go()
{

frame=new JFrame("计算器");
Container cp= frame.getContentPane();
cp.setLayout(new FlowLayout());

b1=new JButton("7");b2=new JButton("8");b3=new JButton("9");b4=new JButton("/");b5=new JButton("1/x");b6=new JButton("sin");b7=new JButton("log");
b8=new JButton("4");b9=new JButton("5");b10=new JButton("6");b11=new JButton("*");b12=new JButton("x^y");b13=new JButton("cos");b14=new JButton("ln");
b15=new JButton("1");b16=new JButton("2");b17=new JButton("3");b18=new JButton("-");b19=new JButton(new ImageIcon("lanying.gif"));b20=new JButton("tan");b21=new JButton("x^3");
b22=new JButton("0");b23=new JButton("+/-");b24=new JButton(".");b25=new JButton("+");b26=new JButton("√x");b27=new JButton("cot");b28=new JButton("x^2");
b29=new JButton("Backspace");b30=new JButton("C");b31=new JButton("=");

mb=new JMenuBar();

m1=new JMenu("文件(F)");m2=new JMenu("编辑(E)");m3=new JMenu("帮助(H)");

mt1=new JMenuItem("清零");mt2=new JMenuItem("退出");mt3=new JMenuItem("复制");mt4=new JMenuItem("粘贴");mt5=new JMenuItem("版本");mt6=new JMenuItem("标准型");mt7=new JMenuItem("科学型");

ta=new JTextArea(1,30);

p1=new JPanel();p2=new JPanel();p3=new JPanel();p4=new JPanel();

rb1=new JRadioButton("科学型");rb2=new JRadioButton("标准型");

bg=new ButtonGroup();

b1.setForeground(Color.blue);b1.setBackground(Color.white);b2.setForeground(Color.blue);b2.setBackground(Color.white);
b3.setForeground(Color.blue);b3.setBackground(Color.white);b8.setForeground(Color.blue);b8.setBackground(Color.white);
b9.setForeground(Color.blue);b9.setBackground(Color.white);b10.setForeground(Color.blue);b10.setBackground(Color.white);
b15.setForeground(Color.blue);b15.setBackground(Color.white);b16.setForeground(Color.blue);b16.setBackground(Color.white);
b17.setForeground(Color.blue);b17.setBackground(Color.white);b22.setForeground(Color.blue);b22.setBackground(Color.white);
b23.setForeground(Color.blue);b23.setBackground(Color.white);b24.setForeground(Color.blue);b24.setBackground(Color.white);

b4.setForeground(Color.red);b4.setBackground(Color.white);b11.setForeground(Color.red);b11.setBackground(Color.white);
b18.setForeground(Color.red);b18.setBackground(Color.white);b25.setForeground(Color.red);b25.setBackground(Color.white);

b5.setForeground(Color.blue);b5.setBackground(Color.white);b6.setForeground(Color.blue);b6.setBackground(Color.white);
b7.setForeground(Color.blue);b7.setBackground(Color.white);b12.setForeground(Color.blue);b12.setBackground(Color.white);
b13.setForeground(Color.blue);b13.setBackground(Color.white);b14.setForeground(Color.blue);b14.setBackground(Color.white);
b19.setForeground(Color.blue);b19.setBackground(Color.white);b20.setForeground(Color.blue);b20.setBackground(Color.white);
b21.setForeground(Color.blue);b21.setBackground(Color.white);b26.setForeground(Color.blue);b26.setBackground(Color.white);
b27.setForeground(Color.blue);b27.setBackground(Color.white);b28.setForeground(Color.blue);b28.setBackground(Color.white);

b29.setForeground(Color.red);b29.setBackground(Color.white);b30.setForeground(Color.red);b30.setBackground(Color.white);
b31.setForeground(Color.red);b31.setBackground(Color.white);

bg.add(rb1);bg.add(rb2);

p1.setBackground(Color.yellow);
cp.setBackground(Color.CYAN);

m1.setMnemonic(KeyEvent.VK_F);m2.setMnemonic(KeyEvent.VK_E);m3.setMnemonic(KeyEvent.VK_H);

m1.add(mt6);m1.add(mt7);m1.addSeparator();m1.add(mt1);m1.addSeparator();m1.add(mt2);m2.add(mt3);m2.addSeparator();m2.add(mt4);m3.add(mt5);
mb.add(m1);mb.add(m2);mb.add(m3);

frame.setJMenuBar(mb);

p2.setLayout(new GridLayout(4,7));
p3.setLayout(new GridLayout(1,3));

ta.setEditable(false);
p1.add(ta);

p2.add(b1);p2.add(b2);p2.add(b3);p2.add(b4);p2.add(b5);p2.add(b6);p2.add(b7);
p2.add(b8);p2.add(b9);p2.add(b10);p2.add(b11);p2.add(b12);p2.add(b13);p2.add(b14);
p2.add(b15);p2.add(b16);p2.add(b17);p2.add(b18);p2.add(b19);p2.add(b20);p2.add(b21);
p2.add(b22);p2.add(b23);p2.add(b24);p2.add(b25);p2.add(b26);p2.add(b27);p2.add(b28);

p3.add(b29);p3.add(b30);p3.add(b31);

Border etched=BorderFactory.createEtchedBorder();
Border border=BorderFactory.createTitledBorder(etched,"计算类型");

p4.add(rb1);p4.add(rb2);
p4.setBorder(border);

b2.setActionCommand("8");
b2.addActionListener(this);

cp.add(p1);cp.add(p4);cp.add(p2);cp.add(p3);

frame.setSize(400,330);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

b1.setActionCommand("7");
b1.addActionListener(this);
b2.setActionCommand("8");
b2.addActionListener(this);
b3.setActionCommand("9");
b3.addActionListener(this);
b4.setActionCommand("/");
b4.addActionListener(this);
b5.setActionCommand("1/x");
b5.addActionListener(this);
b6.setActionCommand("sin");
b6.addActionListener(this);
b7.setActionCommand("log");
b7.addActionListener(this);
b8.setActionCommand("4");
b8.addActionListener(this);
b9.setActionCommand("5");
b9.addActionListener(this);
b10.setActionCommand("6");
b10.addActionListener(this);
b11.setActionCommand("*");
b11.addActionListener(this);
b12.setActionCommand("x^y");
b12.addActionListener(this);
b13.setActionCommand("cos");
b13.addActionListener(this);
b14.setActionCommand("ln");
b14.addActionListener(this);
b15.setActionCommand("1");
b15.addActionListener(this);
b16.setActionCommand("2");
b16.addActionListener(this);
b17.setActionCommand("3");
b17.addActionListener(this);
b18.setActionCommand("-");
b18.addActionListener(this);
b19.setActionCommand("x!");
b19.addActionListener(this);
b20.setActionCommand("tan");
b20.addActionListener(this);
b21.setActionCommand("x^3");
b21.addActionListener(this);
b22.setActionCommand("0");
b22.addActionListener(this);
b23.setActionCommand("+/-");
b23.addActionListener(this);
b24.setActionCommand(".");
b24.addActionListener(this);
b25.setActionCommand("+");
b25.addActionListener(this);
b26.setActionCommand("√x");
b26.addActionListener(this);
b27.setActionCommand("cot");
b27.addActionListener(this);
b28.setActionCommand("x^2");
b28.addActionListener(this);
b29.setActionCommand("Backspace");
b29.addActionListener(this);
b30.setActionCommand("C");
b30.addActionListener(this);
b31.setActionCommand("=");
b31.addActionListener(this);
rb1.setActionCommand("kxx");
rb1.addActionListener(this);
rb2.setActionCommand("bzx");
rb2.addActionListener(this);




}
public void actionPerformed(ActionEvent e) //throws Exception
{


if (e.getActionCommand()=="bzx")
{
b5.setEnabled(false);b6.setEnabled(false);b7.setEnabled(false);
b12.setEnabled(false);b13.setEnabled(false);b14.setEnabled(false);
b19.setEnabled(false);b20.setEnabled(false);b21.setEnabled(false);
b26.setEnabled(false);b27.setEnabled(false);b28.setEnabled(false);

}
if (e.getActionCommand()=="kxx")
{
b5.setEnabled(true);b6.setEnabled(true);b7.setEnabled(true);
b12.setEnabled(true);b13.setEnabled(true);b14.setEnabled(true);
b19.setEnabled(true);b20.setEnabled(true);b21.setEnabled(true);
b26.setEnabled(true);b27.setEnabled(true);b28.setEnabled(true);
}
if (e.getActionCommand()=="1")
{
ta.append("1");
}
if (e.getActionCommand()=="2")
{
ta.append("2");
}
if (e.getActionCommand()=="3")
{
ta.append("3");
}
if (e.getActionCommand()=="4")
{
ta.append("4");
}
if (e.getActionCommand()=="5")
{
ta.append("5");
}
if (e.getActionCommand()=="6")
{
ta.append("6");
}
if (e.getActionCommand()=="7")
{
ta.append("7");
}
if (e.getActionCommand()=="8")
{
ta.append("8");
}
if (e.getActionCommand()=="9")
{
ta.append("9");
}
if (e.getActionCommand()=="0")
{
ta.append("0");
}
if (e.getActionCommand()=="+")
{
s1=ta.getText();
d1 = Double.parseDouble(s1);
ta.setText("");
i=1;
}
if (e.getActionCommand()=="-")
{
s1=ta.getText();
d1 = Double.parseDouble(s1);
ta.setText("");
i=2;
}
if (e.getActionCommand()=="*")
{
s1=ta.getText();
d1 = Double.parseDouble(s1);
ta.setText("");
i=3;
}
if (e.getActionCommand()=="/")
{
s1=ta.getText();
d1 = Double.parseDouble(s1);
ta.setText("");
i=4;
}
if (e.getActionCommand()=="=")
{
s2=ta.getText();
d2=Double.parseDouble(s2);
if(i==1)
{
d3=d1+d2;
ta.setText( d3.toString());
}
if(i==2)
{
d3=d1-d2;
ta.setText( d3.toString());
}
if(i==3)
{
d3=d1*d2;
ta.setText( d3.toString());
}
if(i==4)
{
if(d2==0.0)
ta.setText("ERROR");
else
{
d3=d1/d2;
ta.setText( d3.toString());
}
}
if (i==5)
{
s2=ta.getText();
d2 = Double.parseDouble(s2);
for (int l=1;l<=d2 ; l++)
{
d5=d5*d1;
}
ta.setText( d5.toString());
}


}
if (e.getActionCommand()=="C")
{
ta.setText("");
d4=1.0;
d5=1.0;
}
/*if (e.getActionCommand()=="Backspace")
{
s3=ta.getText();
a=s3.length();
//ta.cut(ta.select(a-1,a));
s4=ta.getText(1,3);
ta.setText(s4);


}
*/
if (e.getActionCommand()=="1/x")
{
s1=ta.getText();
d1 = Double.parseDouble(s1);
d2=1/d1;
ta.setText( d2.toString());

}
if (e.getActionCommand()==".")
{
ta.append(".");
}
if (e.getActionCommand()=="+/-")
{
s1=ta.getText();
d1 = Double.parseDouble(s1);
d2=0-d1;
ta.setText( d2.toString());
}
if (e.getActionCommand()=="x^2")
{
s1=ta.getText();
d1 = Double.parseDouble(s1);
d2=d1*d1;
ta.setText( d2.toString());
}
if (e.getActionCommand()=="x^3")
{
s1=ta.getText();
d1 = Double.parseDouble(s1);
d2=d1*d1*d1;
ta.setText( d2.toString());
}
if (e.getActionCommand()=="x^y")
{
s1=ta.getText();
d1 = Double.parseDouble(s1);
ta.setText("");
i=5;
// d2=d1*d1*d1;
// ta.setText( d2.toString());
}
if (e.getActionCommand()=="√x")
{
s1=ta.getText();
d1 = Double.parseDouble(s1);
d2=Math.sqrt(d1);
ta.setText( d2.toString());
}

if (e.getActionCommand()=="x!")
{
s1=ta.getText();
d1 = Double.parseDouble(s1);
if (d1<0)
{
ta.setText( "error");
}
else if (d1==0)
{
ta.setText( "0.0");
}
else {
for (int k=1;k<=d1 ;k++ )
d4=d4*k;
ta.setText( d4.toString());
}
}
if (e.getActionCommand()=="sin")
{
s1=ta.getText();
d1 = Double.parseDouble(s1);
d2=Math.sin(3.1415926*d1/180);

ta.setText( d2.toString());
}

}

}

以下代码是一个完整的实现,你只要复制过去就可以了~~

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.text.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.undo.*;
import javax.swing.text.*;

public class Start
{
public static void main(String args[])
{
new TextPad();
}
}

class TextPad extends JFrame implements ActionListener
{

JTextArea jta=new JTextArea("小廖记事本:)",18,52);
JCheckBoxMenuItem mto1=new JCheckBoxMenuItem("自动换行",true);
String ss1=jta.getText();
UndoableEditListener ue=new UndoHander();
UndoManager undo = new UndoManager();
int StartFindPos=0,a=0,b=0;
GridBagConstraints gbc=new GridBagConstraints();
//Dimension dd=new Dimension();
// jta.getDocument().addUndoableEditListener(ue);
public TextPad()
{
//MyMenuListener ml=new MyMenuListener();
//JTextArea jta=new JTextArea("This is my textpad",18,52);

//System.out.println(dd.getHeight());
//System.out.println(dd.getWidth());

//System.out.println(this.getHeight());
//System.out.println(this.getWidth());
//System.out.println("OK");
this.setTitle("一个功能比较齐全的JAVA记事本");
this.setLocation(180,100);
jta.setLineWrap(true);
jta.setWrapStyleWord(true);
JPanel jp=new JPanel();
JScrollPane jsp=new JScrollPane(jta);

jp.add(jsp);
//Rectangle rt=new Rectangle(0,0,this.getWidth(),this.getHeight());
//jsp.setBounds(rt);
//System.out.println(this.getHeight());
//System.out.println(this.getWidth());
JMenu mf=new JMenu("文件(F)");
JMenuItem mtf1=new JMenuItem("新建");
mtf1.addActionListener(this);
JMenuItem mtf2=new JMenuItem("打开");
//mtf2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK));
mtf2.addActionListener(this);
JMenuItem mtf3=new JMenuItem("保存");
//mtf3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
mtf3.addActionListener(this);
JMenuItem mtf4=new JMenuItem("另存为");
mtf4.addActionListener(this);
JMenuItem mtf5=new JMenuItem("退出");
mtf5.addActionListener(this);
JMenu me=new JMenu("编辑(E)");
JMenuItem mte1=new JMenuItem("撤消");
mte1.addActionListener(this);
jta.getDocument().addUndoableEditListener(ue);
if(undo.canUndo())
{
mte1.setEnabled(false);
}
JMenuItem mte2=new JMenuItem("剪切");
mte2.addActionListener(this);
JMenuItem mte3=new JMenuItem("复制");
mte3.addActionListener(this);
JMenuItem mte4=new JMenuItem("粘贴");
mte4.addActionListener(this);
//JMenuItem mte5=new JMenuItem("删除");
//mte5.addActionListener(this);
JMenuItem mte6=new JMenuItem("查找");
mte6.addActionListener(this);
//JMenuItem mte7=new JMenuItem("查找下一个");
JMenuItem mte8=new JMenuItem("替换");
mte8.addActionListener(this);
//JMenuItem mte9=new JMenuItem("转到");
JMenuItem mte10=new JMenuItem("全选");
mte10.addActionListener(this);
JMenuItem mte11=new JMenuItem("日期/时间");
mte11.addActionListener(this);
JMenu mo=new JMenu("格式(O)");
//JCheckBoxMenuItem mto1=new JCheckBoxMenuItem("自动换行(W)");
mto1.addActionListener(this);
JMenuItem mto2=new JMenuItem("字体");
mto2.addActionListener(this);
JMenu mv=new JMenu("查看(V)");
JMenuItem mtv1=new JMenuItem("状态栏");
mtv1.setEnabled(false);
JMenu mh=new JMenu("帮助(H)");
JMenuItem mth1=new JMenuItem("关于记事本");
mth1.addActionListener(this);
JMenuBar mb=new JMenuBar();
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
mb.add(mf);
mb.add(me);
mb.add(mo);
mb.add(mv);
mb.add(mh);
this.setJMenuBar(mb);
mf.add(mtf1);
mf.add(mtf2);
mf.add(mtf3);
mf.add(mtf4);
mf.addSeparator();
mf.add(mtf5);
me.add(mte1);
me.addSeparator();
me.add(mte2);
me.add(mte3);
me.add(mte4);
//me.add(mte5);
me.addSeparator();
me.add(mte6);
//me.add(mte7);
me.add(mte8);
//me.add(mte9);
me.addSeparator();
me.add(mte10);
me.add(mte11);
mo.add(mto1);
mo.add(mto2);
mv.add(mtv1);
mh.add(mth1);
this.getContentPane().add(jsp);
this.setSize(600,400);
this.setResizable(true);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{

if(e.getActionCommand().equals("打开"))
{
try
{
Frame f=new Frame();
FileDialog fd=new FileDialog(f,"打开文件",FileDialog.LOAD);
fd.setVisible(true);
String fpath=fd.getDirectory();
String fname=fd.getFile();
BufferedReader br=new BufferedReader(new FileReader(fpath+fname));
jta.setText("");
String s=br.readLine();
while(s!=null)
{
jta.append(s+"\n");
s=br.readLine();
}
br.close();
}
catch(Exception ex)
{
}
}

if(e.getActionCommand().equals("保存"))
{
String fns=null;
Frame f=new Frame("保存");
FileDialog fd=new FileDialog(f,"保存文件",FileDialog.SAVE);
fd.setFile("*.txt");
fd.setVisible(true);
try
{
String savepath=fd.getDirectory();
String savename=fd.getFile();
if(savename!=null)
{
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter(savepath+savename)));
pw.write(jta.getText(),0,jta.getText().length());
pw.flush();
}
}
catch(Exception esave)
{
}
}
if(e.getActionCommand().equals("新建"))
{
jta.setText("");
}
if(e.getActionCommand().equals("另存为"))
{
Frame f=new Frame("保存");
FileDialog fd=new FileDialog(f,"文件另存为",FileDialog.SAVE);
fd.setVisible(true);
try
{
String savepath=fd.getDirectory();
String savename=fd.getFile();
if(savename!=null)
{
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter(savepath+savename)));
pw.write(jta.getText(),0,jta.getText().length());
pw.flush();
}
}
catch(Exception esave)
{
}
}
if(e.getActionCommand().equals("退出"))
{
String ss2=jta.getText();
if(!ss1.equals(ss2))
{
System.out.println("File is changed.");
}
System.exit(0);
}
if(e.getActionCommand().equals("撤消"))
{
try
{
undo.undo();
//System.out.println(undo.canUndo());
}
catch(Exception eundo)
{
}
}
if(e.getActionCommand().equals("剪切"))
{
jta.cut();
}
if(e.getActionCommand().equals("复制"))
{
jta.copy();
}
if(e.getActionCommand().equals("粘贴"))
{
jta.paste();
}
if(e.getActionCommand().equals("删除"))
{

}
if(e.getActionCommand().equals("全选"))
{
jta.selectAll();
}
if(e.getActionCommand().equals("查找"))
{
try
{
final JDialog jd=new JDialog(this,"查找",true);
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
gbc.weightx=0.5;
gbc.weighty=0.5;
gbc.gridwidth=1;
gbc.gridheight=1;
jd.getContentPane().setLayout(gbl);
jd.setSize(380,100);
jd.setResizable(false);
//jd.setDefaultLookAndFeelDecorated(true);
final JTextField jtf=new JTextField(15);
JLabel jlFind=new JLabel("查找内容:");
jd.getContentPane().add(jlFind);
JButton jbFind=new JButton("查找");

jbFind.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent efind)
{
String strA=jta.getText();
String strB=jtf.getText();
if(a>=0)
{
a=strA.indexOf(strB,StartFindPos);

b=strB.length();
StartFindPos=a+b;
if(a==-1)
{
JOptionPane.showMessageDialog(null, "没有您要查找的信息", "查找结果",1);
a=0;
StartFindPos=0;
}
jta.select(a,StartFindPos);
}
}
}
);
JButton jbCancel=new JButton("取消");
jbCancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ejb)
{
jd.dispose();
}
}
);
jd.getContentPane().add(jtf);
jd.getContentPane().add(jbFind);
jd.getContentPane().add(jbCancel);
//jd.setResizable(false);
jd.setLocation(240,200);
jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jd.setVisible(true);
}
catch(Exception efind)
{
}
}
if(e.getActionCommand().equals("替换"))
{
final JDialog jd=new JDialog(this,"替换",true);
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
gbc.weightx=1;
gbc.weighty=1;
gbc.gridwidth=1;
gbc.gridheight=1;
JLabel jlFind=new JLabel("查找:");
JLabel jp=new JLabel("替换内容:");
final JTextField jtf=new JTextField(15);
final JTextField jtf1=new JTextField(15);
jd.getContentPane().setLayout(gbl);
jd.setSize(330,150);
jd.setResizable(false);
final JButton jbReplace=new JButton("替换");
final JButton jbReplaceAll=new JButton("替换所有");
final JButton jbCancel=new JButton("取消");
final JButton jbFind=new JButton("查找");
gbc.gridx=0;
gbc.gridy=0;
jd.getContentPane().add(jlFind,gbc);
gbc.gridx=1;
gbc.gridy=0;
jd.getContentPane().add(jtf1,gbc);
gbc.gridx=2;
gbc.gridy=0;
jd.getContentPane().add(jbFind,gbc);
gbc.gridx=0;
gbc.gridy=1;
jd.getContentPane().add(jp,gbc);
gbc.gridx=1;
gbc.gridy=1;
jd.getContentPane().add(jtf,gbc);
gbc.gridx=2;
gbc.gridy=1;
jd.getContentPane().add(jbReplace,gbc);
gbc.gridx=2;
gbc.gridy=2;
jd.getContentPane().add(jbReplaceAll,gbc);
gbc.gridx=2;
gbc.gridy=3;
jd.getContentPane().add(jbCancel,gbc);
jbFind.addActionListener(new ActionListener()
{

public void actionPerformed(ActionEvent efind)
{
String strA=jta.getText();
String strB=jtf1.getText();
if(a>=0)
{
a=strA.indexOf(strB,StartFindPos);
//System.out.println(a+b);
b=strB.length();
StartFindPos=a+b;
if(a==-1)
{
JOptionPane.showMessageDialog(null, "没有您要查找的信息", "查找结果",1);
a=0;
StartFindPos=0;
}
jta.select(a,StartFindPos);
//System.out.println(StartFindPos);
}
}
}
);
jbReplace.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("替换"))
{
String strRepleace=jtf.getText();
jta.replaceSelection(strRepleace);
}
}
}
);
jbReplaceAll.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{

while(a>-1)
{
String strA=jta.getText();
String strB=jtf1.getText();
a=strA.indexOf(strB,StartFindPos);
if(a==-1)
{
break;
}
//System.out.println(a+b);
b=strB.length();
StartFindPos=a+b;
//System.out.println(StartFindPos);
jta.select(a,StartFindPos);
//System.out.println(StartFindPos);
String strRepleaceAll=jtf.getText();
jta.replaceSelection(strRepleaceAll);
StartFindPos=a+b;

}
JOptionPane.showMessageDialog(null, "全部替换完毕", "替换内容",1);
a=0;
StartFindPos=0;
}
}
);
jbCancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ejb)
{
jd.dispose();
}
}
);
jd.setLocation(240,200);
jd.setVisible(true);
jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
if(e.getActionCommand().equals("日期/时间"))
{
final JDialog jd=new JDialog(this,"插入日期");
JPanel jp1=new JPanel();
jp1.setLayout(new FlowLayout(FlowLayout.LEFT));
final JTextField jtf=new JTextField(10);
JButton jbOK=new JButton("确定");
JButton jbCancel=new JButton("取消");
//Calendar cl=Calendar.getInstance();
//DateFormat df=DateFormat.getInstance();
//String sdate1=df.format(cl.getTime());
//jtf.setText(sdate1);
jp1.add(jtf);
jp1.add(jbOK);
jp1.add(jbCancel);
jd.getContentPane().add(jp1,"North");
JPanel jp2=new JPanel();
jp2.setLayout(new FlowLayout(FlowLayout.LEFT));
final JCheckBox jcb1=new JCheckBox("格式一");
final JCheckBox jcb2=new JCheckBox("格式二");
final JCheckBox jcb3=new JCheckBox("格式三");
jp2.add(jcb1);
jp2.add(jcb2);
jp2.add(jcb3);
jd.getContentPane().add(jp2,"Center");
jd.setSize(220,120);
jd.setResizable(false);
jd.setLocation(240,200);
final SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Calendar cl=Calendar.getInstance();
DateFormat df=DateFormat.getInstance();
final String sdate=df.format(cl.getTime());
jcb1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("格式一"))
{
if(jcb1.isSelected())
{
try
{
SimpleDateFormat sdf1=new SimpleDateFormat("yy年MM月dd日");
Date d=sdf.parse(sdate);
jtf.setText(sdf1.format(d));
jcb2.setEnabled(false);
jcb3.setEnabled(false);
}
catch(Exception estyle1)
{
estyle1.printStackTrace();
}
}
else
{
jcb2.setEnabled(true);
jcb3.setEnabled(true);
}
try
{
System.out.println(jta.getLineStartOffset(3));
//System.out.println(jta.getLineOfOffset(346));
}
catch(Exception eee)
{
}
}
}
}
);
jcb2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("格式二"))
{
if(jcb2.isSelected())
{
try
{
SimpleDateFormat sdf1=new SimpleDateFormat("yy/MM/dd");
Date d=sdf.parse(sdate);
jtf.setText(sdf1.format(d));
jcb1.setEnabled(false);
jcb3.setEnabled(false);
}
catch(Exception estyle2)
{
estyle2.printStackTrace();
}
}
else
{
jcb1.setEnabled(true);
jcb3.setEnabled(true);
}
//System.out.println(jcb1.isSelected());
}
}
}
);
jcb3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("格式三"))
{
if(jcb3.isSelected())
{
jtf.setText(sdate);
jcb1.setEnabled(false);
jcb2.setEnabled(false);
}
else
{
jcb1.setEnabled(true);
jcb2.setEnabled(true);
}
//System.out.println(jcb1.isSelected());
}
}
}
);
jbOK.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("确定"))
{
int pos=jta.getCaretPosition();
jta.insert(jtf.getText(),pos);
}
}
}
);
jbCancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ejb)
{
jd.dispose();
}
}
);
jd.setVisible(true);
jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
if(e.getActionCommand().equals("自动换行"))
{
if(mto1.getState())
{
jta.setLineWrap(true);
jta.setWrapStyleWord(true);
}
else
{
jta.setLineWrap(false);
jta.setWrapStyleWord(false);
}
//System.out.println("OK");
}
if(e.getActionCommand().equals("字体"))
{
final JDialog jd=new JDialog(this,"字体设置");
jd.setLocation(240,200);
//final JFrame jfontview=new JFrame();
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
JButton jbOK=new JButton("确定");
JButton jbCancel=new JButton("取消");
JTextField jtf1=new JTextField(6);
final JTextArea jtaview=new JTextArea(4,8);
//jfontview.getContentPane().add(jtaview);
final JTextField jtf2=new JTextField(6);
final JTextField jtf3=new JTextField(3);
JComboBox jcb1=new JComboBox();
final JComboBox jcb2=new JComboBox();
jcb2.addItem("BOLD");
jcb2.addItem("ITALIC");
jcb2.addItem("PLAIN");
//jcb2.addItem("BOLDITALIC");
jcb2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jtf2.setText((String)jcb2.getSelectedItem());
}
}
);
final JComboBox jcb3=new JComboBox();
jcb3.addItem("14");
jcb3.addItem("18");
jcb3.addItem("22");
jcb3.addItem("26");
jcb3.addItem("30");
jcb3.addItem("34");
jcb3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jtf3.setText((String)jcb3.getSelectedItem());
//jtaview.setText("SS");

// int fontsizeview=Integer.parseInt((String)jcb3.getSelectedItem());
//Font fontview=new Font("字体预览",Font.BOLD,fontsizeview);
//jtaview.setFont(fontview);
//jtaview.setEditable(false);
}
}
);
gbc.gridheight=1;
gbc.gridwidth=1;
//gbc.gridx=1;
//gbc.gridy=0;
gbc.weightx=0.5;
gbc.weighty=0.5;
jd.getContentPane().setLayout(gbl);
//JLabel jl1=new JLabel("预览:");
JLabel jl2=new JLabel("字型:");
JLabel jl3=new JLabel("大小:");
gbc.gridx=0;
gbc.gridy=0;
jd.getContentPane().add(jl2,gbc);
gbc.gridx=2;
gbc.gridy=0;
jd.getContentPane().add(jl3,gbc);
//gbc.gridx=4;
//gbc.gridy=0;
//jd.getContentPane().add(jl3,gbc);
gbc.gridx=0;
gbc.gridy=1;
jd.getContentPane().add(jtf2,gbc);
gbc.gridx=2;
gbc.gridy=1;
jd.getContentPane().add(jtf3,gbc);
//gbc.gridx=4;
// gbc.gridy=1;
//jd.getContentPane().add(jtf3,gbc);
gbc.gridx=0;
gbc.gridy=2;
jd.getContentPane().add(jcb2,gbc);
gbc.gridx=2;
gbc.gridy=2;
jd.getContentPane().add(jcb3,gbc);
//gbc.gridx=4;
//gbc.gridy=2;
//jd.getContentPane().add(jcb3,gbc);
gbc.gridx=4;
gbc.gridy=1;
jd.getContentPane().add(jbOK,gbc);
gbc.gridx=4;
gbc.gridy=2;
jd.getContentPane().add(jbCancel,gbc);
jbOK.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(jtf2.getText().equals("PLAIN"))
{
int fontsize=Integer.parseInt(jtf3.getText());
int fontstyle=0;
Font f=new Font("字体设置",fontstyle,fontsize);
jta.setFont(f);

// System.out.println(f.getFont("楷体_GB2312").getFontName());
}
if(jtf2.getText().equals("BOLD"))
{
int fontsize=Integer.parseInt(jtf3.getText());
int fontstyle=1;
Font f=new Font("字体设置",fontstyle,fontsize);
jta.setFont(f);
}
if(jtf2.getText().equals("ITALIC"))
{
int fontsize=Integer.parseInt(jtf3.getText());
int fontstyle=2;
Font f=new Font("字体设置",fontstyle,fontsize);
jta.setFont(f);
}
jd.dispose();
//System.out.println(fontstyle);
}
}
);
jbCancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jd.dispose();
}
}
);
jd.setSize(200,120);
jd.setResizable(false);
jd.setVisible(true);
jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
if(e.getActionCommand().equals("关于记事本"))
{
JOptionPane jop=new JOptionPane(null,JOptionPane.INFORMATION_MESSAGE);
jop.showMessageDialog(null,"小廖记事本","关于记事本",JOptionPane.OK_OPTION);
//System.out.println("OK");
}

}
class UndoHander implements UndoableEditListener
{
public void undoableEditHappened(UndoableEditEvent eundo)
{
undo.addEdit(eundo.getEdit());
}

}
}

难的就是流那部分了,其他所有的外观的都是很简单的swing或者AWT的组件,直接拿来用就行了,还有个难的就是给组件添加一些快捷键,比如ctrl+c什么的,其他就没了,不过其实流这地方不考虑具体要求性能线程什么的就都用RandomAccessStream什么的那个就是随机读写流就可以完成所有读写操作了,而且是字节流支持中文

以前好像写过练手用的,有空发给你!

用JAVA编写一个记事本~只要实现以下功能:插入~删除~查找~保存~另存为...
答:import java.awt.event.KeyEvent;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileReader;import java.io.FileWriter...

java记事本代码注释
答:import java.awt.*;import java.awt.event.*;import java.io.*;public class tt extends Frame implements ActionListener { static tt frm = new tt();//创建一个菜单栏 static MenuBar menubar = new MenuBar();//创建一个下拉式菜单组件——"文件"static Menu menu1 = new Menu("文件");...

用JAVA编个简单的记事本程序
答:Editor f=new Editor(" 记事本程序"); //添加时间代码 Date date=new Date(); System.out.print(date); /*Calendar now=Calendar.getInstance(); int year=now.get(Calendar.YEAR); int month=now.get(Calendar.MONTH)+1; int day=now.get(Calendar.DATE); System.out.print(year+"年"+month+"月"+...

使用记事本编写JAVA程序,并运行输出结果,具体的实现步骤是什么?_百度...
答:1、首先在电脑中新建一个记事本,将记事本的后缀改为“.java”,如下图所示。2、然后使用记事本的方式打开,输入java程序代码,如下图所示。3、接着在键盘上按“win+R”快捷键键打开运行,输入“cmd”,如下图所示。4、在命令行输入“D:”,按“Enter”键进去D盘,再输入“cd Desktop”进去...

【紧急求助】求简单JAVA记事本程序
答:String message = "---记事本---\n版本:Version 1.0\n 感谢您的使用!"; JOptionPane.showMessageDialog(Notepad.this, message, "关于...",JOptionPane.PLAIN_MESSAGE); } else if (o == open) { //打开文件 save(isChangered, isOpened); FileDialog openFile = new FileDialog(Notepad.this, "打开文件...

用java编写记事本(输入,打开,保存功能就行)或者计算器(实现加减乘除就...
答:import java.awt.*;import javax.swing.*;import java.awt.event.*;public class Calculator extends JFrame implements ActionListener { private JTextField text;StringBuffer sb1 = new StringBuffer(); //参数一 StringBuffer sb2 = new StringBuffer(); //参数二 private double b;private double...

求Java记事本源代码
答:setTitle("我的记事本");setSize(500, 600);setContentPane(createContentPane());//添加主面板 } /*创建主面板*/ private JPanel createContentPane() { JPanel pane = new JPanel(new BorderLayout());pane.add(BorderLayout.NORTH, createChocePane());//添加菜单栏 pane.add(createAreaPane...

求JAVA记事本代码(十万火急!越快越好!)
答:super("记事本");fileMenu = new JMenu("文件(F)");// ==文件菜单 fileMenu.setMnemonic('F');newMenu = new JMenuItem("新建(N)"); // 新建项 newMenu.setMnemonic('N');fileMenu.add(newMenu);fileMenu.addSeparator(); // 添加分割线 newMenu.setAccelerator(KeyStroke.getKeyStroke(Key...

java的一个简单记事本程序设计
答:是记事本的样式吗?就要这些要求吗?下面这些代码的功能挺全的,可以参考一下,不用的可以删掉。import java.io.*;import java.util.Calendar;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;public class NoteBook extends JFrame implements ActionListener,ItemListener...

如何用记事本编写JAVA程序
答:、先下个JDK。。。然后单击我的电脑属性,在高级里面设计环境变量。。然后在计事本中写程序,如果是运行程序那么类名要和文件名一样。文件名的拓展名为.java。然后在命令提示符里输入你java文件的目录位置,运行javac XXX.java 然后运行java XXX就可以运行了。。至于记事本中怎么写你自己看着办。。

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网