Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * frmFo.java
- *
- * Created on 2011. october 22., 7:12PM
- */
- import java.io.*;
- import javax.swing.*;
- import javax.swing.JFileChooser.*;
- import java.io.FileNotFoundException.*;
- /**
- *
- * @author zegige
- */
- public class frmFo extends javax.swing.JFrame {
- FileReader fr;
- FileWriter fw;
- File fcDir;
- String fNev="Anonymous.txt";
- JFileChooser jfc;
- String vagolap;
- /** Creates new form frmFo */
- public frmFo() {
- 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">
- private void initComponents() {
- jToolBar1 = new javax.swing.JToolBar();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jButton3 = new javax.swing.JButton();
- jButton4 = new javax.swing.JButton();
- jButton5 = new javax.swing.JButton();
- jButton6 = new javax.swing.JButton();
- jButton7 = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- epSzoveg = new javax.swing.JEditorPane();
- jPanel1 = new javax.swing.JPanel();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- lbKarakter = new javax.swing.JLabel();
- lbSzavak = new javax.swing.JLabel();
- lbMondatok = new javax.swing.JLabel();
- jMenuBar1 = new javax.swing.JMenuBar();
- jMenu1 = new javax.swing.JMenu();
- mnuNew = new javax.swing.JMenuItem();
- mnuOpen = new javax.swing.JMenuItem();
- mnuSave = new javax.swing.JMenuItem();
- mnuSaveAs = new javax.swing.JMenuItem();
- mnuPrint = new javax.swing.JMenuItem();
- mnuExit = new javax.swing.JMenuItem();
- jMenu2 = new javax.swing.JMenu();
- jMenuItem7 = new javax.swing.JMenuItem();
- jMenuItem8 = new javax.swing.JMenuItem();
- jMenuItem9 = new javax.swing.JMenuItem();
- jMenuItem10 = new javax.swing.JMenuItem();
- jSeparator1 = new javax.swing.JSeparator();
- jMenuItem11 = new javax.swing.JMenuItem();
- jMenu4 = new javax.swing.JMenu();
- jMenu3 = new javax.swing.JMenu();
- jMenu5 = new javax.swing.JMenu();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/new.gif"))); // NOI18N
- jToolBar1.add(jButton1);
- jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/open.gif"))); // NOI18N
- jButton2.setFocusable(false);
- jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
- jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- OpenFile(evt);
- }
- });
- jToolBar1.add(jButton2);
- jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/save.gif"))); // NOI18N
- jButton3.setFocusable(false);
- jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
- jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
- jButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- SaveFile(evt);
- }
- });
- jToolBar1.add(jButton3);
- jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/copy.gif"))); // NOI18N
- jButton4.setFocusable(false);
- jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
- jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
- jButton4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- Masol(evt);
- }
- });
- jToolBar1.add(jButton4);
- jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cut.gif"))); // NOI18N
- jButton5.setFocusable(false);
- jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
- jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
- jButton5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- Kivagas(evt);
- }
- });
- jToolBar1.add(jButton5);
- jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/paste.gif"))); // NOI18N
- jButton6.setFocusable(false);
- jButton6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
- jButton6.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
- jButton6.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- Beilleszt(evt);
- }
- });
- jToolBar1.add(jButton6);
- jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/help.png"))); // NOI18N
- jButton7.setFocusable(false);
- jButton7.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
- jButton7.setMaximumSize(new java.awt.Dimension(31, 31));
- jButton7.setMinimumSize(new java.awt.Dimension(31, 31));
- jButton7.setPreferredSize(new java.awt.Dimension(31, 31));
- jButton7.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
- jButton7.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton7ActionPerformed(evt);
- }
- });
- jToolBar1.add(jButton7);
- epSzoveg.addKeyListener(new java.awt.event.KeyAdapter() {
- public void keyTyped(java.awt.event.KeyEvent evt) {
- Nyomi(evt);
- }
- });
- jScrollPane1.setViewportView(epSzoveg);
- jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
- jLabel1.setText("Karakterek sz·ma:");
- jLabel2.setText("Szavak sz·ma:");
- jLabel3.setText("Mondatok sz·ma:");
- lbKarakter.setText("0");
- lbSzavak.setText("0");
- lbMondatok.setText("0");
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(lbKarakter, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(67, 67, 67)
- .addComponent(jLabel2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(lbSzavak, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(43, 43, 43)
- .addComponent(jLabel3)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(lbMondatok, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(56, Short.MAX_VALUE))
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(jLabel2)
- .addComponent(jLabel3)
- .addComponent(lbKarakter)
- .addComponent(lbSzavak)
- .addComponent(lbMondatok))
- .addContainerGap(13, Short.MAX_VALUE))
- );
- jMenuBar1.setMaximumSize(new java.awt.Dimension(200, 32769));
- jMenuBar1.setPreferredSize(new java.awt.Dimension(200, 21));
- jMenu1.setText("File");
- mnuNew.setText("⁄j");
- mnuNew.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- UjFile(evt);
- }
- });
- jMenu1.add(mnuNew);
- mnuOpen.setText("Megnyit·s");
- mnuOpen.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- OpenFile(evt);
- }
- });
- jMenu1.add(mnuOpen);
- mnuSave.setText("MentÈs");
- mnuSave.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- SaveFile(evt);
- }
- });
- jMenu1.add(mnuSave);
- mnuSaveAs.setText("MentÈs m·skÈnt...");
- mnuSaveAs.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- SaveFile(evt);
- }
- });
- jMenu1.add(mnuSaveAs);
- mnuPrint.setText("Nyomtat·s");
- jMenu1.add(mnuPrint);
- mnuExit.setText("KilÈpÈs");
- mnuExit.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- Kilep(evt);
- }
- });
- jMenu1.add(mnuExit);
- jMenuBar1.add(jMenu1);
- jMenu2.setText("SzerkesztÈs");
- jMenuItem7.setText("Visszavon·s");
- jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- Visszavon(evt);
- }
- });
- jMenu2.add(jMenuItem7);
- jMenuItem8.setText("M·sol·s");
- jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- Masol(evt);
- }
- });
- jMenu2.add(jMenuItem8);
- jMenuItem9.setText("Kiv·g·s");
- jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- Kivagas(evt);
- }
- });
- jMenu2.add(jMenuItem9);
- jMenuItem10.setText("BeillesztÈs");
- jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- Beilleszt(evt);
- }
- });
- jMenu2.add(jMenuItem10);
- jMenu2.add(jSeparator1);
- jMenuItem11.setText("KeresÈs");
- jMenu2.add(jMenuItem11);
- jMenuBar1.add(jMenu2);
- jMenu4.setText("NÈzet");
- jMenuBar1.add(jMenu4);
- jMenu3.setText("Form·z·s");
- jMenuBar1.add(jMenu3);
- jMenu5.setText("SegÌtsÈg");
- jMenuBar1.add(jMenu5);
- setJMenuBar(jMenuBar1);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGap(456, 456, 456))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 569, Short.MAX_VALUE))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 294, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- );
- pack();
- }// </editor-fold>
- private void Kilep(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- System.exit(0);
- }
- private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void OpenFile(java.awt.event.ActionEvent evt) {
- String szoveg;
- jfc=new JFileChooser();
- jfc.setApproveButtonText("Megnyit·s");
- jfc.setDialogTitle("File nyit·sa");
- if(jfc.showOpenDialog(this)==0){
- fcDir=jfc.getSelectedFile();
- this.fNev=jfc.getName(fcDir);
- this.setTitle("Megnyitott file:"+this.fNev);
- try{
- fr=new FileReader(fcDir);
- szoveg="";
- while(fr.ready()){
- szoveg=szoveg+String.valueOf((char)fr.read());
- }
- epSzoveg.setText(szoveg);
- fr.close();
- Szamol();
- }catch(java.io.FileNotFoundException fnf){
- //¸zenni kell
- }
- catch(java.io.IOException ioe){
- //¸zenni kell
- }
- }
- }
- private void SaveFile(java.awt.event.ActionEvent evt) {
- if(this.fNev.length()==0){
- this.fNev="Anonymous.txt";
- }
- jfc=new JFileChooser();
- jfc.setApproveButtonText("MentÈs");
- jfc.setDialogTitle("File z·r·sa");
- jfc.setName(fNev);
- if(jfc.showSaveDialog(this)==0){
- try{
- fcDir=jfc.getSelectedFile();
- this.fNev=jfc.getName(fcDir);
- fw=new FileWriter(fcDir);
- fw.write(epSzoveg.getText());
- fw.close();
- }catch(java.io.FileNotFoundException fnf){
- //¸zenni kell
- }
- catch(java.io.IOException ioe){
- //¸zenni kell
- }
- }else{
- }
- }
- private void UjFile(java.awt.event.ActionEvent evt) {
- int hossz;
- String szoveg;
- szoveg=epSzoveg.getText(); // kiolvassa a epSzoveg tartalm·t
- hossz=szoveg.length(); // szoveg hossza
- if(hossz>0){
- if(JOptionPane.showConfirmDialog(this, "A munkater¸let nem ¸res!Tˆrˆlhetem?")==JOptionPane.OK_OPTION){
- epSzoveg.setText("");
- this.fNev="Anonymous.txt";
- }
- }else this.fNev="Anonymous.txt";
- }
- private void Masol(java.awt.event.ActionEvent evt) {
- epSzoveg.copy();
- }
- private void Kivagas(java.awt.event.ActionEvent evt) {
- this.vagolap=epSzoveg.getText();
- epSzoveg.cut();
- }
- private void Beilleszt(java.awt.event.ActionEvent evt) {
- this.vagolap=epSzoveg.getText();
- epSzoveg.paste();
- }
- private void Visszavon(java.awt.event.ActionEvent evt) {
- epSzoveg.setText(this.vagolap);
- }
- private void Nyomi(java.awt.event.KeyEvent evt) {
- Szamol();
- }
- private void Szamol(){
- int hossz,szsz,msz,i;
- char kar;
- String szoveg;
- szsz=msz=i=0;
- hossz=epSzoveg.getText().length();
- if(hossz>0){
- szoveg=epSzoveg.getText();
- while(i<hossz){
- while(i<hossz && ElvalasztoJel(kar=szoveg.charAt(i))){
- ++i;
- }
- if(i<hossz) szsz++;
- while(i<hossz && !ElvalasztoJel(kar=szoveg.charAt(i))){
- ++i;
- }
- }
- lbKarakter.setText(String.valueOf(hossz));
- lbSzavak.setText(String.valueOf(szsz));
- lbMondatok.setText("0");
- }
- }
- private boolean ElvalasztoJel(char kar){
- boolean ret=false;
- switch(kar){
- case ' ':
- case ',':
- case ';':
- case '-':
- case '.':
- case '!':
- case '?':
- case '"':
- case '_':
- case '\r':
- case '\n':
- case '(':
- case ')':
- case '{':
- case '}':
- case ']':
- case '[':
- ret=true;
- }
- return ret;
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new frmFo().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JEditorPane epSzoveg;
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JButton jButton3;
- private javax.swing.JButton jButton4;
- private javax.swing.JButton jButton5;
- private javax.swing.JButton jButton6;
- private javax.swing.JButton jButton7;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JMenu jMenu1;
- private javax.swing.JMenu jMenu2;
- private javax.swing.JMenu jMenu3;
- private javax.swing.JMenu jMenu4;
- private javax.swing.JMenu jMenu5;
- private javax.swing.JMenuBar jMenuBar1;
- private javax.swing.JMenuItem jMenuItem10;
- private javax.swing.JMenuItem jMenuItem11;
- private javax.swing.JMenuItem jMenuItem7;
- private javax.swing.JMenuItem jMenuItem8;
- private javax.swing.JMenuItem jMenuItem9;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JSeparator jSeparator1;
- private javax.swing.JToolBar jToolBar1;
- private javax.swing.JLabel lbKarakter;
- private javax.swing.JLabel lbMondatok;
- private javax.swing.JLabel lbSzavak;
- private javax.swing.JMenuItem mnuExit;
- private javax.swing.JMenuItem mnuNew;
- private javax.swing.JMenuItem mnuOpen;
- private javax.swing.JMenuItem mnuPrint;
- private javax.swing.JMenuItem mnuSave;
- private javax.swing.JMenuItem mnuSaveAs;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement