简易记事本java源代码 记事本怎么编写java( 十 )


if(num==-1)
break;
temp=temp+new String(b,0,num);
}
fis.close();
}
catch (Exception e1)
{
e1.printStackTrace();
}
return temp;
}
public void write()
{
try
{
FileOutputStream fos=new FileOutputStream(f);
fos.write(jta.getText().getBytes());
fos.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void newNew()
{
frame.dispose();
new MyNotepad();
flag=true;
}
public MyNotepad()
{
JMenuBar jmb=new JMenuBar();
String[] menuLab={"文件","编辑","帮助"};
String[][] menuItemLab={{"新建","打开","保存","另存","退出"},
{"撤销","剪切","复制","粘贴","删除","全选","查找","替换"},
{"版本"}};
for(int i=0;imenuLab.length;i++)
{
JMenu menu=new JMenu(menuLab[i]);
jmb.add(menu);
for(int j=0;jmenuItemLab[i].length;j++)
{
JMenuItem jmi=new JMenuItem(menuItemLab[i][j]);
menu.add(jmi);
jmi.addActionListener(this);
}
}
frame.setJMenuBar(jmb);
jta.setLineWrap(true);//自动换行
JScrollPane jsp=new JScrollPane(jta);//滚动窗口面板
frame.add(jsp);
jb.addActionListener(this);
jbt.addActionListener(this);
jba.addActionListener(this);
frame.setLocation(200,50);
frame.setSize(620,660);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
new MyNotepad();
}
}
java简单记事本源代码 带解释import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
classtest 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);

推荐阅读