📄 cswf.java
字号:
import java.io.IOException;
import java.io.*;
import java.lang.Object;
import java.util.*;
/*
* CSWF.java
*
* Created on 2007年5月30日, 下午5:38
*/
/**
*
* @author Administrator
*/
public class CSWF extends javax.swing.JFrame {
// this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
/** Creates new form CSWF */
LinkedList wordlist;
String [] word=new String[60000];
long wordnum=0;
public CSWF() {
wordlist=new LinkedList();
BufferedReader reader = null;
String str = null;
try {
reader=new BufferedReader(new InputStreamReader(new
FileInputStream("WordTable.txt")));
str = reader.readLine();
} catch (Exception ex) {
ex.printStackTrace();
}
while(str!=null){
wordlist.add(str);
try {
str = reader.readLine();
} catch (IOException ex) {
ex.printStackTrace();
}
}
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
inputext = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
outputext = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("\u6587\u672c");
jLabel2.setText("\u5206\u8bcd");
jButton1.setText("\u5207\u5206");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
inputext.setColumns(20);
inputext.setRows(5);
jScrollPane1.setViewportView(inputext);
outputext.setColumns(20);
outputext.setRows(5);
jScrollPane2.setViewportView(outputext);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(29, 29, 29)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel1)
.add(jLabel2))
.add(23, 23, 23)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(jScrollPane2)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE))
.addContainerGap(32, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap(200, Short.MAX_VALUE)
.add(jButton1)
.add(143, 143, 143))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(30, 30, 30)
.add(jLabel1))
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 25, Short.MAX_VALUE)
.add(jButton1)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(56, 56, 56)
.add(jLabel2))
.add(layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(42, 42, 42))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
Object source=evt.getSource();
int j;
String t = null;
if(source==jButton1) {
String result="/";
String str=inputext.getText();
//parse the input string
int wordendloc=str.length();
for(int i=str.length()-1;i>=0;i--)
{
//System.out.println(str.substring(i,i+1));
if(i<0)
break;
// boolean isword=false;
while(true){
if(i<0) break;
t=str.substring(i,wordendloc);
for(j=0;j<wordlist.size()&&j<32767;j++){
String temp=(String)wordlist.get(j);
System.out.println(temp+":"+t);
if(t.compareTo(temp)==0)
{
break;
}
}
if(j>=wordlist.size()||j>=32767)
{
result="/"+t.substring(1,t.length())+result;
wordendloc=i+1;
System.out.println(result);
break;
}
i--;
}
}
result=t.substring(0,t.length())+result;
this.outputext.setText(result);
}
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CSWF().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextArea inputext;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea outputext;
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -