十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
如楼上所说,但如果你把
创新互联建站是一家专业的成都网站建设公司,我们专注网站制作、网站建设、网络营销、企业网站建设,买友情链接,一元广告为企业客户提供一站式建站解决方案,能带给客户新的互联网理念。从网站结构的规划UI设计到用户体验提高,创新互联力求做到尽善尽美。
后缀名
设置隐藏的话,可以用"另存为"来保存,并将保存类型选为"所有文件",然后输入你的文件名,注意要加后缀.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class f1 extends Frame implements ActionListener
{
private MenuBar menubar=new MenuBar();
private Menu filemenu=new Menu("文件");
private Menu editmenu=new Menu("编辑");
private Menu formmenu=new Menu("格式");
private MenuItem[] itemf=new MenuItem[4];
private MenuItem[] iteme=new MenuItem[6];
private MenuItem[] items=new MenuItem[2];
private TextArea tf=new TextArea();
public int a=0,b=0,c=0,style=Font.PLAIN,size=15;
public String s1="red:"+a+" "+"green:"+b+" "+"blue"+c,
s2="宋体";
public String[] sz1={"10","16","24","30","32","36"},
sz2={"宋体","黑体","幼圆","隶书","行楷","Arial","Georgia"},
sz3={"粗体","倾斜","常规","粗斜"};
JDialog dialog=new JDialog(this,"字体",true);
Container cp=dialog.getContentPane();
JLabel[] lb=new JLabel[8];
JLabel lb1=new JLabel(s1,JLabel.LEFT);
JButton b1=new JButton("确定"),
b2=new JButton("取消");
JComboBox jc1=new JComboBox(),
jc2=new JComboBox(),
jc3=new JComboBox();
JScrollBar jb1=new JScrollBar(JScrollBar.HORIZONTAL,10,5,0,260);
JScrollBar jb2=new JScrollBar(JScrollBar.HORIZONTAL,10,5,0,260);
JScrollBar jb3=new JScrollBar(JScrollBar.HORIZONTAL,10,5,0,260);
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.*; //Date needed
import java.io.PrintWriter;
public class NotePad extends JFrame
{
JTextArea jta;
class newl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.setText("");
}
}
class openl implements ActionListener
{ public void actionPerformed(ActionEvent e)
{
JFileChooser jf=new JFileChooser();
jf.showOpenDialog(NotePad.this);
}
}
//保存文件的监听
class savel implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFileChooser jf = new JFileChooser();
jf.showSaveDialog(NotePad.this);
}
}
//打印的监听 ?
class printl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
// PrintWriter p = new PrintWriter(NotePad.this);
}
}
//退出记事本的监听
class exitl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);//退出
}
}
//拷贝的监听
class copyl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.copy();
}
}
//粘贴的监听
class pastel implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.paste();
}
}
//剪切的监听
class cutl implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.cut();
}
}
//查找的监听
//添加日期的监听
class datel implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Date d=new Date();
jta.append(d.toString());
}
}
//构造函数
public NotePad()
{
jta=new JTextArea("",24,40);
JScrollPane jsp=new JScrollPane(jta);
JMenuBar jmb=new JMenuBar();
JMenu mFile=new JMenu("File");
JMenu mEdit=new JMenu("Edit");
JMenuItem mNew=new JMenuItem("New",KeyEvent.VK_N);
mNew.addActionListener(new newl());
mFile.add(mNew);
JMenuItem mOpen=new JMenuItem("Open",KeyEvent.VK_O);
mOpen.addActionListener(new openl());
mFile.add(mOpen);
JMenuItem mSave=new JMenuItem("Save");
mSave.addActionListener(new savel());
mFile.add(mSave);
mFile.addSeparator(); //添加分割线
JMenuItem mPrint = new JMenuItem("Print");
mPrint.addActionListener(new printl());
mFile.add(mPrint);
mFile.addSeparator(); //添加分割线
JMenuItem mExit=new JMenuItem("Exit");
mExit.addActionListener(new exitl());
mFile.add(mExit);
mFile.setMnemonic(KeyEvent.VK_F);
//编辑菜单的子菜单的处理
JMenuItem jmi;
jmi=new JMenuItem("Copy");
jmi.addActionListener(new copyl());
mEdit.add(jmi);
jmi=new JMenuItem("Cut");
jmi.addActionListener(new cutl());
mEdit.add(jmi);
jmi=new JMenuItem("Paste");
jmi.addActionListener(new pastel());
mEdit.add(jmi);
mEdit.addSeparator(); //添加分割线
jmi=new JMenuItem("Find");
mEdit.add(jmi);
jmi=new JMenuItem("FindNext");
mEdit.add(jmi);
mEdit.addSeparator();
jmi=new JMenuItem("Select All");
mEdit.add(jmi);
jmi=new JMenuItem("Date/Time");
jmi.addActionListener(new datel());
mEdit.add(jmi);
jmb.add(mFile);
jmb.add(mEdit);
this.setJMenuBar(jmb);
this.getContentPane().add(jsp);
this.setSize(200,200);
this.setVisible(true);
}
//主函数,程序入口点
public static void main(String s[])
{
new NotePad();
}
}
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
public class MenuTester extends JFrame implements ActionListener
{
private static final long serialVersionUID = 1L;
private static final String FILE = "d:/1.txt";
JTextArea textArea;
JScrollPane scrollPane;
public MenuTester ()
{
setTitle ("MenuTester");
setLayout (new BorderLayout ());
JMenuBar menuBar = new JMenuBar ();
JMenu[] menu = new JMenu[] { new JMenu ("文件"), new JMenu ("编辑") };
JMenuItem[] menuItem1 = new JMenuItem[] { new JMenuItem ("新建"), new JMenuItem ("打开"), new JMenuItem ("保存"), new JMenuItem ("关闭") };
JMenuItem[] menuItem2 = new JMenuItem[] { new JMenuItem ("复制"), new JMenuItem ("粘贴"), new JMenuItem ("剪切") };
for ( int i = 0; i menu.length; i++ )
{
menuBar.add (menu[i]);
}
for ( int i = 0; i menuItem1.length; i++ )
{
menu[0].add (menuItem1[i]);
}
for ( int i = 0; i menuItem2.length; i++ )
{
menu[1].add (menuItem2[i]);
}
menuItem1[0].addActionListener (this);
menuItem1[1].addActionListener (this);
menuItem1[2].addActionListener (this);
menuItem1[3].addActionListener (this);
setJMenuBar (menuBar);
textArea = new JTextArea ();
scrollPane = new JScrollPane (textArea);
scrollPane.setVisible (false);
add (scrollPane, BorderLayout.CENTER);
setResizable (false);
setSize (800, 600);
setLocationRelativeTo (null);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setVisible (true);
}
public static void main ( String[] args )
{
SwingUtilities.invokeLater (new Runnable ()
{
@Override
public void run ()
{
new MenuTester ();
}
});
}
@Override
public void actionPerformed ( ActionEvent e )
{
String command = e.getActionCommand ();
if ("新建".equals (command))
{
scrollPane.setVisible (true);
validate ();
}
else if ("关闭".equals (command))
{
scrollPane.setVisible (false);
textArea.setText ("");
validate ();
}
else if ("打开".equals (command))
{
scrollPane.setVisible (true);
validate ();
try
{
FileReader fr = new FileReader (FILE);
char[] cs = new char[1];
while (-1 != ( fr.read (cs) ))
{
textArea.append (new String (cs));
}
fr.close ();
}
catch (Exception e1)
{
e1.printStackTrace ();
}
}
else if ("保存".equals (command))
{
try
{
FileWriter fw = new FileWriter (FILE);
fw.write (textArea.getText ());
fw.flush ();
fw.close ();
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
}
}