1、设定虚拟内存
硬盘中有一个很宠大的数据交换文件,它是系统预留给虚拟内存作暂存的地方,很多应用程序都经常会使用到,所以系统需要经常对主存储器作大量的数据存取,因此存取这个档案的速度便构成影响计算机快慢的非常重要因素!一般Windows预设的是由系统自行管理虚拟内存,它会因应不同程序所需而自动调校交换档的大小,但这样的变大缩小会给系统带来额外的负担,令系统运作变慢!有见及此,用户最好自定虚拟内存的最小值和最大值,避免经常变换大小。要设定虚拟内存,在“我的电脑”上按右键选择“属性”,在“高级”选项里的“效能”的对话框中,对“虚拟内存”进行设置。
3、检查应用软件或者驱动程序
有些程序在电脑系统启动会时使系统变慢。如果要是否是这方面的原因,我们可以从“安全模式”启动。因为这是原始启动,“安全模式”运行的要比正常运行时要慢。但是,如果你用“安全模式”启动发现电脑启动速度比正常启动时速度要快,那可能某个程序是导致系统启动速度变慢的原因。
4、桌面图标太多会惹祸
桌面上有太多图标也会降低系统启动速度。Windows每次启动并显示桌面时,都需要逐个查找桌面快捷方式的图标并加载它们,图标越多,所花费的时间当然就越多。同时有些杀毒软件提供了系统启动扫描功能,这将会耗费非常多的时间,其实如果你已经打开了杀毒软件的实时监视功能,那么启动时扫描系统就显得有些多余,还是将这项功能禁止吧! 建议大家将不常用的桌面图标放到一个专门的文件夹中或者干脆删除!
5、ADSL导致的系统启动变慢
默认情况下Windows XP在启动时会对网卡等网络设备进行自检,如果发现网卡的IP地址等未配置好就会对其进行设置,这可能是导致系统启动变慢的真正原因。这时我们可以打开“本地连接”属性菜单,双击“常规”项中的“Internet协议”打开“TCP/IP属性”菜单。将网卡的IP地址配置为一个在公网(默认的网关是192.168.1.1)中尚未使用的数值如192.168.1.X,X取介于2~255之间的值,子网掩码设置为255.255.255.0,默认网关和DNS可取默认设置。
import java.io.*import java.awt.event.*
import java.awt.*
import javax.swing.*
import javax.swing.filechooser.*
import javax.swing.event.*
import java.math.*
import java.awt.image.BufferedImage
import java.awt.Toolkit
public class NotePad extends JFrame implements ActionListener,ItemListener{
JButton b_save,b_close
JTextArea textArea
boolean isCurrentFileExists=false
File tempFile
JPanel jp
JMenu file,edit,style,help
JCheckBoxMenuItem s_autoLine
JMenuItem f_new,f_open,f_save,f_close,f_saveas,e_copy,e_paste,e_cut,e_clear,e_selectAll,s_font,s_color,h_editor
JMenuBar jmb
JScrollPane jsp
JPopupMenu popUpMenu=new JPopupMenu()
JLabel stateBar
JLabel j1,jstate
JFileChooser jfc=new JFileChooser()
JMenuItem je_copy,je_paste,je_cut,je_clear,je_selectAll
public NotePad() //构造函数,初始化
{
jp = new JPanel()
// j1 = new JLabel("JAVA记事本")
// jstate = new JLabel("状态栏:")
jmb = new JMenuBar() //初始化菜单栏
textArea = new JTextArea() //初始化编辑窗口
jsp = new JScrollPane(textArea)
file = new JMenu("File")
edit = new JMenu("Edit")
style = new JMenu("Style")
help = new JMenu("SOS")
je_copy=new JMenuItem("Copy")
je_paste=new JMenuItem("Paste")
je_cut=new JMenuItem("Cut")
je_clear=new JMenuItem("Clear")
je_selectAll=new JMenuItem("SelectAll")
je_copy.addActionListener(this)
je_paste.addActionListener(this)
je_cut.addActionListener(this)
je_clear.addActionListener(this)
je_selectAll.addActionListener(this)
f_new = new JMenuItem("New")
f_new.addActionListener(this)
f_open = new JMenuItem("Open")
f_open.addActionListener(this)
f_save = new JMenuItem("Save")
f_save.addActionListener(this)
f_saveas = new JMenuItem("Save as")
f_saveas.addActionListener(this)
f_close = new JMenuItem("Close")
f_close.addActionListener(this)
e_copy = new JMenuItem("Copy")
e_copy.addActionListener(this)
e_paste = new JMenuItem("Paste")
e_paste.addActionListener(this)
e_cut = new JMenuItem("Cut")
e_cut.addActionListener(this)
e_clear=new JMenuItem("Clear")
e_clear.addActionListener(this)
e_selectAll=new JMenuItem("SelectAll")
e_selectAll.addActionListener(this)
s_font=new JMenuItem("Font")
s_font.addActionListener(this)
s_color=new JMenuItem("Color")
s_color.addActionListener(this)
s_autoLine=new JCheckBoxMenuItem("AutoLine",true)
s_autoLine.addItemListener(this)
h_editor = new JMenuItem("About")
h_editor.addActionListener(this)
stateBar = new JLabel("NewFile")
stateBar.setHorizontalAlignment(SwingConstants.LEFT)
stateBar.setBorder(BorderFactory.createEtchedBorder())
//添加右键弹出式菜单
//popUpMenu = edit.getPopupMenu()
popUpMenu.add(je_copy)
popUpMenu.add(je_paste)
popUpMenu.add(je_cut)
popUpMenu.add(je_clear)
// 编辑区键盘事件
textArea.addKeyListener(
new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
stateBar.setText("已修改")
}
})
// 编辑区鼠标事件,点击右键弹出"编辑"菜单
textArea.addMouseListener(
new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
if(e.getButton() == MouseEvent.BUTTON3)
popUpMenu.show(e.getComponent(), e.getX(), e.getY())
}
public void mouseClicked(MouseEvent e) {
if(e.getButton() == MouseEvent.BUTTON1)
popUpMenu.setVisible(false)
}
}
)
this.setJMenuBar(jmb)
this.setTitle("记事本")
Image image=this.getToolkit().getImage("zheng.gif")
this.setIconImage(image)
file.add(f_new)
file.add(f_open)
file.add(f_save)
file.add(f_saveas)
file.add(f_close)
edit.add(e_copy)
edit.add(e_paste)
edit.add(e_cut)
edit.add(e_clear)
edit.add(e_selectAll)
style.add(s_autoLine)
style.add(s_font)
style.add(s_color)
help.add(h_editor)
jmb.add(file)
jmb.add(edit)
jmb.add(style)
jmb.add(help)
b_save = new JButton("保存")
b_save.addActionListener(this)
b_close = new JButton("关闭")
b_close.addActionListener(this)
this.add(jsp)
this.setSize(800,600)
this.setVisible(true)
//设置窗口居中显示
int W = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth()
int H = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight()
this.setLocation((W-this.getWidth())/2,(H-this.getHeight())/2)
//为窗口添加"关闭"事件的响应
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE)
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
whenExit()
}
})
} /////////////创建工作完成//////////////////
//响应菜单项"自动换行"的事件
public void itemStateChanged(ItemEvent event)
{
if(event.getSource()==s_autoLine)
{
if(s_autoLine.getState())
{
textArea.setLineWrap(true)
}
else
textArea.setLineWrap(false)
}
}
//判断文件是否被修改
public boolean isCurrentFileSaved()
{
if(stateBar.getText().equals("已保存")||stateBar.getText().equals("新文档"))
{
return true
}
else {
return false
}
}
//打开文件对话框
public void openFileDialog()
{
int m=jfc.showOpenDialog(this)
if(m== JFileChooser.APPROVE_OPTION)
{
File f=jfc.getSelectedFile()
for(int i=0i<=f.length()i++)
{
char [] ch = new char[i]
try{
FileReader fr = new FileReader(f)
fr.read(ch)
String str = new String(ch)
textArea.setText(str)
isCurrentFileExists=true
tempFile=f
}
catch(FileNotFoundException fe )
{JOptionPane.showMessageDialog(null,"未找到需要打开的文件!") }
catch(IOException ie)
{ System.err.println(ie)}
}
}
else
return
}
//保存文件对话框
public void saveFileDialog()
{
int options=jfc.showSaveDialog(this)
String fname = null
if(options == JFileChooser.APPROVE_OPTION)
{
File f = jfc.getSelectedFile()//如果没有选取文件,下面的jfc.getName(f)将会返回输入的文件名
fname = jfc.getName(f)
if(fname != null &&fname.trim().length()>0)
{
if(fname.endsWith(".txt"))
else
{
fname = fname.concat(".txt")
}
}
if(f.isFile())
fname = f.getName()
f = jfc.getCurrentDirectory()
f = new File(f.getPath().concat(File.separator).concat(fname))
if(f.exists())
{
int i=JOptionPane.showConfirmDialog(null,"该文件已经存在,确定要覆盖吗?")
if(i ==JOptionPane.YES_OPTION)
else
return
}
try{
f.createNewFile()
String str=textArea.getText()
FileWriter fw = new FileWriter(f)
fw.write(str)
fw.close()
isCurrentFileExists=true
tempFile=f
stateBar.setText("已保存")
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, "出错:"+ ex.getMessage())
return
}
}
}
//剪切
public void cut() {
textArea.cut()
stateBar.setText("已修改")
popUpMenu.setVisible(false)
}
//复制
public void copy() {
textArea.copy()
popUpMenu.setVisible(false)
}
//粘贴
public void paste() {
textArea.paste()
stateBar.setText("已修改")
popUpMenu.setVisible(false)
}
//清除
public void clear(){
textArea.replaceRange("",textArea.getSelectionStart(),textArea.getSelectionEnd())
stateBar.setText("已修改")
popUpMenu.setVisible(false)
}
//全选
public void selectAll(){
textArea.selectAll()
}
//当退出程序时判断文档状态
public void whenExit()
{
if(isCurrentFileSaved()) //关闭窗口时判断是否保存了文件
{
dispose()
System.exit(0)
}
else
{
int i=JOptionPane.showConfirmDialog(null,"文件未保存,是否要保存?","提示",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE)
if(i ==JOptionPane.YES_OPTION)
saveFileDialog()
else if(i==JOptionPane.NO_OPTION)
{
dispose()
System.exit(0)
}
else
return
}
}
public void actionPerformed(ActionEvent e)
{
//响应菜单项"新建"的事件
if(e.getSource()==f_new)
{
if(isCurrentFileSaved())
{
textArea.setText("")
stateBar.setText("新文档")
}
else
{
int i=JOptionPane.showConfirmDialog(null,"文件未保存,是否要保存?","提示",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE)
if(i ==JOptionPane.YES_OPTION)
saveFileDialog()
else if(i==JOptionPane.NO_OPTION)
{
textArea.setText("")
stateBar.setText("新文档")
}
else
return
}
}
//响应菜单项"打开"的事件
if(e.getSource()==f_open)
{
if(isCurrentFileSaved())
{
openFileDialog()
}
else
{
int i=JOptionPane.showConfirmDialog(null,"文件未保存,是否要保存?","提示",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE)
if(i ==JOptionPane.YES_OPTION)
saveFileDialog()
else if(i==JOptionPane.NO_OPTION)
{
openFileDialog()
}
else
return
}
}
//响应菜单项"保存"和"按钮"保存"的事件
if((e.getSource()==b_save)||(e.getSource()==f_save))
{
if(isCurrentFileExists)
{
try{
String str=textArea.getText()
FileWriter fw = new FileWriter(tempFile)
fw.write(str)
fw.close()
isCurrentFileExists=true
tempFile=tempFile
stateBar.setText("已保存")
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, "出错:"+ ex.getMessage())
return
}
}
else
saveFileDialog()
}
//响应菜单"另存为"的事件
if(e.getSource()==f_saveas)
{
int option=jfc.showDialog(this,"另存为")
String fname = null
if(option == JFileChooser.APPROVE_OPTION)
{
File f = jfc.getSelectedFile()//如果没有选取文件,下面的jfc.getName(f)将会返回输入的文件名
fname = jfc.getName(f)
if(fname != null &&fname.trim().length()>0)
{
if(fname.endsWith(".txt"))
else
{
fname = fname.concat(".txt")
}
}
if(f.isFile())
fname = f.getName()
f = jfc.getCurrentDirectory()
f = new File(f.getPath().concat(File.separator).concat(fname))
if(f.exists())
{
int i=JOptionPane.showConfirmDialog(null,"该文件已经存在,确定要覆盖吗?")
if(i ==JOptionPane.YES_OPTION)
else
return
}
try{
f.createNewFile()
String str=textArea.getText()
FileWriter fw = new FileWriter(f)
fw.write(str)
fw.close()
stateBar.setText("已保存")
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, "出错:"+ ex.getMessage())
return
}
}
else
{
JOptionPane.showMessageDialog(null,"文件没有保存!")
}
}
//响应"退出"菜单和"关闭"按钮的事件
if((e.getSource()==f_close)||(e.getSource()==b_close))
{
whenExit()
}
if(e.getSource()==e_copy||e.getSource()==je_copy)
{
copy()
}
if(e.getSource()==e_paste||e.getSource()==je_paste)
{
paste()
}
if(e.getSource()==e_cut||e.getSource()==je_cut)
{
cut()
}
if(e.getSource()==e_clear||e.getSource()==je_clear)
{
clear()
}
if(e.getSource()==e_selectAll||e.getSource()==je_selectAll)
{
selectAll()
}
if(e.getSource()==s_font) //创建字体选择对话框
{
Font font
font =new Font("新宋体",Font.PLAIN,12)
font = FontChooser.showDialog(this,null,font)
if(font!=null)//判断是否选择了"确定"按钮
{
textArea.setFont(font)
}
else
{
textArea.setFont(textArea.getFont())
}
}
if(e.getSource()==s_color) //创建颜色选择对话框
{
Color c=JColorChooser.showDialog(this,"请选择文字颜色",Color.cyan)
if(c!=null)
{
textArea.setForeground(c)
}
else
textArea.setForeground(textArea.getForeground())
}
if(e.getSource()==h_editor)
{
JOptionPane.showMessageDialog(this,"计科06级5班,小郑同学,200631500155\n superle@vip.qq.com ","关于记事本",JOptionPane.INFORMATION_MESSAGE)
}
}
public static void main (String[] args) //创建一个NotePad的匿名对象
{
new NotePad()
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* 此字体对话框的使用方法
* Font font = null
* font = FontChooser.showDialog(this,null,font)
* textArea.setFont(font)
*/
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
class FontChooser extends JDialog
{
String[] styleList = new String[]
{"常规","粗体","斜体" ,"粗斜体"}
String[] sizeList = new String[]
{"3","4","5","6","7","8","9","10","11","12","13","14","15","16","17",
"18","19","20","22","24","26","28","30","34","39","45","50","60","72"}
MyList StyleList
MyList FontList
MyList SizeList
static JLabel Sample = new JLabel()
public static boolean isSelected = false
private FontChooser(Frame parent,boolean modal,Font font)
{
super (parent,modal)
initAll()
setTitle("字体")
if (font == null) font = Sample.getFont()
FontList.setSelectedItem(font.getName())
SizeList.setSelectedItem(font.getSize()+"")
StyleList.setSelectedItem(styleList[font.getStyle()])
}
public static Font showDialog(Frame parent,String s,Font font)
{
FontChooser fd = new FontChooser(parent,true,font)
if (s != null) fd.setTitle(s)
fd.setVisible(true)
Font fo = null
if (fd.isSelected) fo = Sample.getFont() //如果选择OK按钮,则获取字体
fd.dispose()
return(fo)
}
private void initAll()
{
getContentPane().setLayout(null)
int W = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth()
int H = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight()
setBounds((W-425)/2,(H-400)/2,430,400) //设置字体窗口居屏幕中间显示
addLists()
addButtons()
Sample.setBounds(10,312,400,28)
Sample.setForeground(Color.black)
getContentPane().add(Sample)
addWindowListener(new WindowAdapter()
{public void windowClosing(java.awt.event.WindowEvent e)
{
setVisible (false)
isSelected=false
}
})
}
private void addLists()
{
FontList = new MyList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames())
StyleList = new MyList(styleList)
SizeList = new MyList(sizeList)
FontList.setBounds(10,10,260,295)
StyleList.setBounds(280,10,80,295)
SizeList.setBounds(370,10,40,295)
getContentPane().add(FontList)
getContentPane().add(StyleList)
getContentPane().add(SizeList)
}
private void addButtons()
{
JButton ok = new JButton("确定")
ok.setMargin(new Insets(0,0,0,0))
JButton ca = new JButton("取消")
ca.setMargin(new Insets(0,0,0,0))
ok.setBounds(260,350,70,20)
ok.setFont(new Font(" ",1,12))
ca.setBounds(340,350,70,20)
ca.setFont(new Font(" ",1,12))
getContentPane().add(ok)
getContentPane().add(ca)
ok.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent e)
{
setVisible(false)
isSelected = true
}
})
ca.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent e)
{
setVisible(false)
isSelected = false
}
})
}
private void showSample()
{
int g = 0
try {g = Integer.parseInt(SizeList.getSelectedValue())}
catch(NumberFormatException nfe){}
String st = StyleList.getSelectedValue()
int s = Font.PLAIN
if (st.equalsIgnoreCase("粗体")) s = Font.BOLD
if (st.equalsIgnoreCase("斜体")) s = Font.ITALIC
if (st.equalsIgnoreCase("粗斜体")) s = Font.ITALIC | Font.BOLD
Sample.setFont(new Font(FontList.getSelectedValue(),s,g))
Sample.setHorizontalAlignment(SwingConstants.LEFT)
Sample.setBorder(BorderFactory.createEtchedBorder())
Sample.setText("效果预览,abcdefg")
}
public class MyList extends JPanel
{
JList jl
JScrollPane sp
JLabel jt
String si = " "
public MyList(String[] values)
{
setLayout(null)
jl = new JList(values)
sp = new JScrollPane(jl)
jt = new JLabel()
jt.setBackground(Color.white)
jt.setForeground(Color.black)
jt.setOpaque(true)
jt.setBorder(new JTextField().getBorder())
jt.setFont(getFont())
jl.setBounds(0,0,100,1000)
jl.setBackground(Color.white)
jl.addListSelectionListener(new ListSelectionListener()
{public void valueChanged(ListSelectionEvent e)
{
jt.setText((String)jl.getSelectedValue())
si = (String)jl.getSelectedValue()
showSample()
}
})
add(sp)
add(jt)
}
public String getSelectedValue()
{
return(si)
}
public void setSelectedItem(String s)
{
jl.setSelectedValue(s,true)
}
public void setBounds(int x, int y, int w ,int h)
{
super.setBounds(x,y,w,h)
sp.setBounds(0,y+12,w,h-23)
sp.revalidate()
jt.setBounds(0,0,w,20)
}
}
}
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)