java程序,java 记事本 小程序打开。大佬们帮帮忙,在线等,急,看看什么毛病。

Java 如何实现打开PDF文件,并把文件显示出来;就是实现文件打开的功能。急,急...._百度知道
Java 如何实现打开PDF文件,并把文件显示出来;就是实现文件打开的功能。急,急....
我有更好的答案
java打开PDF需要借助其他的jar包的,如果我没记错的话,然后查看相应的API接口。应该是以流的形式进行读取,之前写过一点是往里面写数据的,生成html文然后写入PDF文件 工具有:ItextPdf、FlyingAndItext、pd4ml
这些是将html文转换为PDF文件的,读取的话直接用bufferread读取试试(我没写过!)
为您推荐:
其他类似问题
pdf文件的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。Java – hellojavacases微信公众号网站
2018年一月
891011121314
15161718192021
22232425262728
2017年七月 &(1)
2017年一月 &(1)
2016年十二月 &(1)
2016年十月 &(1)
2016年九月 &(4)
2016年七月 &(2)
2016年六月 &(2)
2016年五月 &(2)
2016年四月 &(1)
2016年三月 &(4)
2015年十月 &(1)
2015年七月 &(1)
2015年六月 &(1)
2015年五月 &(1)
2015年四月 &(1)
2015年三月 &(2)
2015年一月 &(2)
2014年十一月 &(1)
2014年十月 &(2)
2014年九月 &(2)
2014年八月 &(2)
2014年七月 &(1)
2014年六月 &(1)
2014年五月 &(2)
2014年四月 &(4)
2014年三月 &(3)
2014年二月 &(4)
2014年一月 &(1)
2013年十二月 &(4)
2013年十一月 &(4)
2013年十月 &(3)
2013年九月 &(3)
2013年八月 &(5)
2013年七月 &(4)
2013年六月 &(1)
2013年五月 &(6)
2013年四月 &(12)
2013年三月 &(3)
上篇文章中附加了一个最近碰到的奇怪的case,有位同学看到这个后周末时间折腾了下,把原因给分析出来了,分析过程很赞,非常感谢这位同学(阿里的一位同事,花名叫彦贝),在征求他的同意后,我把他写的整个问题的分析文章转载到这里。
上分析工具VisualVM
在解决很多问题的时候,工具起的作用往往是巨大,很多时候通过工具分析,很快便能找到原因,但是这次并没有,下图是VisualVM观察到Heap上的GC图表。
从图标中可以看出,Perm区空间基本水平,但是Old区空间成增长态势与YGCT时间增长的倍率基本一直。熟悉YGC的朋友都知道YGC主要分为标记和收回两个阶段,YGCT也是基于这2个阶段统计的。由于每次回收的空间大小差不多,所以怀疑是标记阶段使用的时间比较长,下面回顾一下JVM的垃圾标记方式。
JVM垃圾回收的标记方法-枚举根节点
在Java语言里面,可作为GC Roots的节点主要在全局性的引用(例如常量或类静态属性)与执行上下文(例如栈帧中的本地变量表)中。如果要使用可达性分析来判断内存是否可回收的,那分析工作必须在一个能保障一致性的快照中进行——这里“一致性”的意思是整个分析期间整个执行系统看起来就像被冻结在某个时间点上,不可以出现分析过程中,对象引用关系还在不断变化的情况,这点不满足的话分析结果准确性就无法保证。这点也是导致GC进行时必须“Stop The World”的其中一个重要原因,即使是号称(几乎)不会发生停顿的CMS收集器中,枚举根节点时也是必须要停顿的。
由于目前的主流JVM使用的都是准确式GC,所以当执行系统停顿下来之后,并不需要一个不漏地检查完所有执行上下文和全局的引用位置,虚拟机应当是有办法直接得到哪些地方存放着对象引用。在HotSpot的实现中,是使用一组成为OopMap的数据结构来达到这个目的,在类加载完成的时候,HotSpot就把对象内什么偏移量上是什么类型的数据计算出来,在JIT编译过程中,也会在特定的位置记录下栈里和寄存器里哪些位置是引用。这样GC在扫描时就就可以直接得知这些信息了。
上面这段引用自《深入理解Java虚拟机》,用个图简单表示一下,当然图也是源于书中:
基于对GC Roots的怀疑,猜测Old区中存在越来越多的gc root节点,那什么样的对象是root节点呢?不懂的我赶紧google了一下。
(不要看我红色圈出来了,第一次看到这几个嫌疑犯时我也拿不准是哪个)
为了进一步验证是Old区的GC Roots造成YGCT 增加的,我们来做一次full gc,干掉Old区。代码如下:
public class SlowYGC {
public static void main(String[] args) throws Exception {
while (true) {
XStream xs = new XStream();
xs.toString();
if(i++ % 10000 == 0)
System.gc();
可以看出Full GC后 YGCT锐减到初始状态。那是Full GC到底回收了哪些对象?进入到下一步,增加VM参数。
增加VM参数
为了看到Full GC前后对象的回收情况,我们增加下面2个VM参数
-XX:+PrintClassHistogramBeforeFullGC -XX:+PrintClassHistogramAfterFullGC。
重新运行上面的代码,可以观察到下面的日志:
上图左边是FGC前的对象情况,右边是FGC后的情况,结合我之前给出的GC Root候选人中的Monitor锁,相信你很快就找到20026个[Ljava.util.concurrent.ConcurrentHashMap$Segment对象几乎被全部回收了,ConcurrentHashMap中正是通过Segment来实现分段锁的。那什么逻辑会导致出现大量的Segment锁对象。继续看Full GC日志com.thoughtworks.xstream.core.util.CompositeClassLoader这个对象也差不多在FGC的时候全军覆没,所以怀疑是ClassLoader引起的锁竞争,下面在ClassLoader的源码中继续查找。
ClassLoader中的ConcurrentHashMap
这里有个拿锁的动作,跟进去看看呗。
为了验证走到这块逻辑下了一个断点。剩下的就是putIfAbsent方法(这里就不详细分析实现了)有兴趣的同学可以看看源码中CAS和tryLock的使用。
至此基本分析和定位出了YGCT原因,在去看看Xstream的构造函数。
可以看出每次new XstreamI()的同时会new一个新的ClassLoader,基本上证明了上述怀疑和猜测。
推导一下按照上述分析,应该是所有自定义的ClassLoader都会YGCT变长的时间问题,于是手写一个ClassLoader验证一下。Java代码如下:
public class TestClassLoader4YGCT {
public static void main(String[] args) throws Exception{
while(true)
Object obj = newObject();
obj.toString();
private static Object newObject() throws Exception
ClassLoader classLoader = new ClassLoader() {
public Class loadClass(String s) throws ClassNotFoundException {
String fileName = s.substring(s.lastIndexOf(“.”) + 1)+ “.class”;
InputStream inputStream = getClass().getResourceAsStream(fileName);
if(inputStream == null){
return super.loadClass(s);
byte[] b = new byte[inputStream.available()];
inputStream.read(b);
return defineClass(s,b,0,b.length);
}catch (Exception e)
System.out.println(e);
Class obj = classLoader.loadClass(“jvmstudy.classload.TestClassLoader4YGCT”);
return obj.newInstance();
VM 参数-XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xms512m -Xmx512m -Xmn100m -XX:+UseConcMarkSweepGC
当大量new自定义的ClassLoader来加载时,会产生大量ClassLoader对象以及parallelLockMap(ConcurrentHashMap)对象,导致产生大量的Segment分段锁对象,大大增加了GC Roots的数量,导致YGC中的标记时间变长。如果能直接看到YGCT的详细使用情况,这个结论会显得更加严谨。这只是我自己的一个推导,并不一定是正确答案。
=============================
欢迎关注微信公众号:hellojavacases
关于此微信号:
分享Java问题排查的Case、Java业界的动态和新技术、Java的一些小知识点Test,以及和大家一起讨论一些Java问题或场景,这里只有Java细节的分享,没有大道理、大架构和大框架。
公众号上发布的消息都存放在http://hellojava.info上。import java.awt.BorderL
import java.awt.C
import java.awt.C
import java.awt.C
import java.awt.FileD
import java.awt.FlowL
import java.awt.F
import java.awt.GraphicsE
import java.awt.GridBagC
import java.awt.GridL
import java.awt.LayoutM
import java.awt.L
import java.awt.event.ActionE
import java.awt.event.ActionL
import java.awt.event.InputE
import java.awt.event.MouseA
import java.awt.event.MouseE
import java.awt.event.MouseL
import java.awt.event.WindowA
import java.awt.event.WindowE
import java.awt.event.WindowL
import java.awt.image.BufferedI
import java.io.BufferedR
import java.io.BufferedW
import java.io.FileD
import java.io.FileR
import java.io.FileW
import java.io.PrintW
import javax.swing.JB
import javax.swing.JColorC
import javax.swing.JD
import javax.swing.JF
import javax.swing.JL
import javax.swing.JM
import javax.swing.JMenuB
import javax.swing.JMenuI
import javax.swing.JOptionP
import javax.swing.JP
import javax.swing.JPopupM
import javax.swing.JScrollP
import javax.swing.JTextA
import javax.swing.JTextF
import javax.swing.KeyS
import javax.swing.ScrollPaneC
import javax.swing.JInternalFrame.JDesktopI
import javax.swing.event.DocumentE
import javax.swing.event.DocumentL
import sun.security.jca.JCAU
public class notepad extends JFrame {
private static final long serialVersionUID = 1L;
private JTextArea ja = new JTextArea(5, 6);
private String fileP
private String fileN
// 自动换行和状态栏
int a = 0;
boolean flag = false;
public jishiben() {
super("记事本");
this.setSize(768, 384);
this.setLocationRelativeTo(null);
JMenu wj = new JMenu();
wj.setText("文件");
JMenu bj = new JMenu("编辑");
JMenu gs = new JMenu("格式");
JMenu ck = new JMenu("查看");
JMenu bz = new JMenu("帮助");
JMenuBar gjl = new JMenuBar();
// 菜单项定义
final JMenuItem open = new JMenuItem();
open.setText("打开");
JMenuItem New = new JMenuItem();
New.setText("新建");
JMenuItem save = new JMenuItem();
save.setText("保存");
final JMenuItem saveas = new JMenuItem();
saveas.setText("另存为&");
JMenuItem exit = new JMenuItem();
exit.setText("退出");
final JMenuItem copy = new JMenuItem();
copy.setText("复制");
final JMenuItem cut = new JMenuItem();
cut.setText("剪切");
JMenuItem paste = new JMenuItem();
paste.setText("粘贴");
final JMenuItem selectall = new JMenuItem();
selectall.setText("全选");
JMenuItem auto = new JMenuItem();
auto.setText("自动换行");
final JMenuItem font = new JMenuItem();
font.setText("字体");
JMenuItem about = new JMenuItem();
about.setText("关于记事本&");
JMenuItem ztl = new JMenuItem();
ztl.setText("状态栏");
// 菜单项添加(文件菜单)
wj.add(open);
wj.add(New);
wj.add(save);
wj.add(saveas);
wj.addSeparator();
wj.add(exit);
// 菜单项添加(编辑菜单)
bj.add(cut);
bj.add(copy);
bj.add(paste);
bj.addSeparator();
bj.add(selectall);
// 菜单项添加(格式菜单)
gs.add(auto);
gs.add(font);
// 菜单项添加(查看菜单)
ck.add(ztl);
// 菜单项添加(帮助菜单)
bz.add(about);
// 把各个菜单添加到菜单栏
gjl.add(wj);
gjl.add(bj);
gjl.add(gs);
gjl.add(ck);
gjl.add(bz);
this.setJMenuBar(gjl);
this.add(ja);
JLabel lbfont = new JLabel("字体");
JLabel lbsize = new JLabel("大小");
JLabel lbshape = new JLabel("字形");
JPanel jpfont1 = new JPanel();
JPanel jpfont2 = new JPanel();
JPanel jpfont3 = new JPanel();
JPanel jpfont4 = new JPanel();
final JFrame fontMain = new JFrame();
final JDialog fontJd = new JDialog(fontMain, "字体,颜色,调色板", true);
JButton ok = new JButton("确定");
final JButton canel = new JButton("取消");
JButton color = new JButton("颜色");
final List fontList = new List(10, false);
final List fontShape = new List(10, false);
final List sizeList = new List(10, false);
// 加系统字体
String[] fontNames = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getAvailableFontFamilyNames();
for (int i = 0; i & fontNames. i++) {
fontList.add(fontNames[i]);
// 字体形状
fontShape.add("常规");
fontShape.add("粗体");
fontShape.add("斜体");
fontShape.add("粗斜体");
// 设置字体对话框
fontJd.setSize(450, 300);
jpfont1.add(lbfont);
jpfont1.add(fontList);
jpfont2.add(lbsize);
jpfont2.add(lbshape);
jpfont3.add(lbshape);
jpfont3.add(fontShape);
jpfont4.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 10));
jpfont4.add(ok);
jpfont4.add(canel);
jpfont4.add(color);
fontJd.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
fontJd.add(jpfont1);
fontJd.add(jpfont2);
fontJd.add(jpfont3);
fontJd.add(jpfont4);
fontList.select(a);
sizeList.select(4);
fontShape.select(0);
// 字体大小
final String[] size = { "1", "2", "3", "4", "5", "6", "7", "8", "9",
for (int i = 0; i & size. i++) {
sizeList.add(size[i]);
// 设置颜色按钮监听器
color.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JColorChooser jcolor = new JColorChooser();
Color fcolor = ja.getForeground();
ja.setForeground(jcolor.showDialog(ja, "选择字体颜色", fcolor));
// 取消按钮监听器
canel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fontMain.setVisible(false);
// 确定按钮监听器
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fontMain.setVisible(false);
// 字体监听器
font.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fontJd.setLocationRelativeTo(jishiben.this);
fontJd.setVisible(true);
int style = 0;
if (fontShape.getSelectedItem().equals("常规") == true) {
style = Font.PLAIN;
if (fontShape.getSelectedItem().equals("斜体") == true) {
style = Font.ITALIC;
if (fontShape.getSelectedItem().equals("粗体") == true) {
style = Font.BOLD;
if (fontShape.getSelectedItem().equals("粗斜体") == true) {
style = Font.BOLD + Font.ITALIC;
// 设置字体大小
String[] size = { "1", "2", "3", "4", "5", "6", "7", "8", "9",
for (int i = 0; i & size. i++) {
if (sizeList.getSelectedItem().equals(size[i]) == true) {
ja.setFont(new Font(String.valueOf(fontList
.getSelectedItem()), style, (10 - i) * 10));
fontJd.dispose();
// 文件改变事件
ja.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
flag = true;
public void insertUpdate(DocumentEvent e) {
flag = true;
public void removeUpdate(DocumentEvent e) {
flag = true;
// 窗口监听器
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent w) {
fileName = jishiben.this.getTitle();
if (flag == true) {
int returnValue = JOptionPane.showConfirmDialog(null,
jishiben.this.getTitle() + "文件还没有保存!需要保存?", "记事本",
JOptionPane.YES_NO_CANCEL_OPTION);
if (returnValue == JOptionPane.YES_OPTION) {
save_asMethod();
} else if (returnValue == JOptionPane.NO_OPTION) {
System.exit(0);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
// 退出时用到的保存文件函数
public void save_asMethod() {
FileDialog fd = new FileDialog(jishiben.this, "另存为&",
FileDialog.SAVE);
fd.setFile("*.txt");
fd.setVisible(true);
filePath = fd.getDirectory();
fileName = fd.getFile();
FileWriter fw = new FileWriter(filePath + fileName);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
pw.println(ja.getText());
pw.flush();
pw.close();
} catch (Exception ex) {
ex.printStackTrace();
// 右键快捷方式
final JPopupMenu jp = new JPopupMenu();
final JMenuItem jcopy = new JMenuItem("复制");
final JMenuItem jpaste = new JMenuItem("粘贴");
final JMenuItem jcut = new JMenuItem("剪切");
final JMenuItem jselectall = new JMenuItem("全选");
final JMenuItem jfont = new JMenuItem("字体");
jp.add(jcopy);
jp.add(jpaste);
jp.add(jcut);
jp.addSeparator();
jp.add(jselectall);
jp.addSeparator();
jp.add(jfont);
// 右键菜单之字体的事件
// 右键菜单之复制的事件
jcopy.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ja.copy();
// 右键菜单之粘贴的事件
jpaste.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ja.paste();
// 右键菜单之剪切的事件
jcut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 右键菜单之全选的事件
jselectall.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ja.selectAll();
// 右键菜单之增加鼠标事件
ja.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
jp.show((Component) (e.getSource()), e.getX(), e.getY());
String temp = ja.getSelectedText();
if (temp != null) {
copy.setEnabled(true);
cut.setEnabled(true);
jcopy.setEnabled(true);
jcut.setEnabled(true);
} else if (temp == null) {
copy.setEnabled(false);
cut.setEnabled(false);
jcopy.setEnabled(false);
jcut.setEnabled(false);
String temp1 = ja.getText();
if (temp1 == null) {
selectall.setEnabled(false);
jselectall.setEnabled(false);
} else if (temp1 != null) {
selectall.setEnabled(true);
jselectall.setEnabled(true);
// 复制菜单项
copy.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ja.copy();
// 粘贴菜单项
paste.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ja.paste();
} catch (Exception ex) {
ex.printStackTrace();
// 剪切菜单项
cut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
} catch (Exception ex) {
ex.printStackTrace();
// 全选菜单项
selectall.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ja.selectAll();
// 换行菜单项
auto.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (a == 0) {
ja.setLineWrap(true);
} else if (a == 1) {
ja.setLineWrap(false);
// 新建菜单项
New.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jishiben.this.setTitle("无标题&&记事本.txt");
ja.setText(" ");
// 退出菜单项
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fileName = jishiben.this.getTitle();
if (flag == true) {
int returnValue = JOptionPane.showConfirmDialog(null,
jishiben.this.getTitle() + "文件还没有保存!需要保存?", "记事本",
JOptionPane.YES_NO_CANCEL_OPTION);
if (returnValue == JOptionPane.YES_OPTION) {
save_asMethod();
} else if (returnValue == JOptionPane.NO_OPTION) {
System.exit(0);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
public void save_asMethod() {
FileDialog fd = new FileDialog(jishiben.this, "另存为&",
FileDialog.SAVE);
fd.setFile("*.txt");
fd.setVisible(true);
filePath = fd.getDirectory();
fileName = fd.getFile();
FileWriter fw = new FileWriter(filePath + fileName);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
pw.println(ja.getText());
pw.flush();
pw.close();
} catch (Exception ex) {
ex.printStackTrace();
// 保存菜单项
save.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fileName = jishiben.this.getTitle();
FileWriter fw = new FileWriter(fileName + ".txt");
String save = ja.getText();
fw.write(save);
fw.close();
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "文件已经成功保存了!", "文件保存",
JOptionPane.INFORMATION_MESSAGE);
// 另存菜单项
saveas.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
FileDialog fd = new FileDialog(jishiben.this, "另存为&",
FileDialog.SAVE);
fd.setFile("*.txt");
fd.setVisible(true);
filePath = fd.getDirectory();
fileName = fd.getFile();
FileWriter fw = new FileWriter(filePath + fileName);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
pw.println(ja.getText());
pw.flush();
pw.close();
} catch (Exception ex) {
ex.printStackTrace();
// 打开菜单项
open.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FileDialog fd1 = new FileDialog(jishiben.this, "打开",
FileDialog.LOAD);
fd1.setFile("*.txt");
fd1.setVisible(true);
fileName = fd1.getFile();
filePath = fd1.getDirectory();
jishiben.this.setTitle(fileName);
FileReader fr = new FileReader(filePath + fileName);
BufferedReader br = new BufferedReader(fr);
String sinput = "";
ja.setText("");
int lineNum = 0;
while ((sinput = br.readLine()) != null) {
// System.out.println(sinput);
ja.append(sinput + "\r\n");
lineNum++;
} catch (Exception ex) {
ex.printStackTrace();
// 关于菜单项
final JFrame jfm = new JFrame();
JLabel lb1 = new JLabel("本记事本有zyw制作\n");
JLabel lb2 = new JLabel("版权所有,盗版必究!\n");
JLabel lb3 = new JLabel("谢谢使用!\n");
jfm.setSize(200, 170);
jfm.setTitle("关于本软件");
jfm.add(lb1);
jfm.add(lb2);
jfm.add(lb3);
final JButton qd = new JButton("确定");
qd.setSize(20, 17);
jfm.add(qd);
// 关于菜单项
about.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jfm.setLocationRelativeTo(jishiben.this);
jfm.setVisible(true);
jfm.setLayout(new GridLayout(4, 1, 5, 10));
jfm.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 10));
qd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jfm.setVisible(false);
// 状态栏菜单项
final JLabel lb = new JLabel();
ztl.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (a == 1) {
lb.setVisible(false);
} else if (a == 0) {
jishiben.this.add(lb, BorderLayout.SOUTH);
lb.setVisible(true);
lb.setText("当前字数: "
+ String.valueOf(ja.getText().trim().length())
+ " " + "当前行数: "
+ String.valueOf(ja.getLineCount()));
open.setAccelerator(KeyStroke.getKeyStroke('O', InputEvent.CTRL_MASK));
New.setAccelerator(KeyStroke.getKeyStroke('N', InputEvent.CTRL_MASK));
save.setAccelerator(KeyStroke.getKeyStroke('S', InputEvent.CTRL_MASK));
exit.setAccelerator(KeyStroke.getKeyStroke('Q', InputEvent.CTRL_MASK));
copy.setAccelerator(KeyStroke.getKeyStroke('C', InputEvent.CTRL_MASK));
paste.setAccelerator(KeyStroke.getKeyStroke('V', InputEvent.CTRL_MASK));
cut.setAccelerator(KeyStroke.getKeyStroke('X', InputEvent.CTRL_MASK));
selectall.setAccelerator(KeyStroke.getKeyStroke('A',
InputEvent.CTRL_MASK));
auto.setAccelerator(KeyStroke.getKeyStroke('H', InputEvent.CTRL_MASK));
font.setAccelerator(KeyStroke.getKeyStroke('F', InputEvent.ALT_MASK));
// 添加滚动条
JScrollPane jsp = new JScrollPane(ja);
Container c = this.getContentPane();
c.add(jsp);
jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); // 需要的时候出现
jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); // 总是存在
this.setVisible(true);
private static String change(String s) {
byte abyte0[] = s.getBytes();
char ac[] = new char[s.length()];
int i = 0;
for (int k = abyte0. i & i++) {
int j = abyte0[i];
if (j &= 48 && j &= 57)
j = ((j - 48) + 5) % 10 + 48;
else if (j &= 65 && j &= 90)
j = ((j - 65) + 13) % 26 + 65;
else if (j &= 97 && j &= 122)
j = ((j - 97) + 13) % 26 + 97;
ac[i] = (char)
return String.valueOf(ac);
public static void main(String[] args) {
jishiben jsb = new jishiben();
阅读(...) 评论()
友情链接:

我要回帖

更多关于 java编写记事本程序 的文章

 

随机推荐