Advertisement
Guest User

bbb

a guest
Oct 15th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.41 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. import java.awt.Graphics;
  7. import java.io.*;
  8. import java.util.logging.Level;
  9. import java.util.logging.Logger;
  10. import javax.swing.ImageIcon;
  11. import javax.swing.JFileChooser;
  12. /**
  13.  *
  14.  * @author labor
  15.  */
  16. public class NewJFrame extends javax.swing.JFrame {
  17.  
  18.     /**
  19.      * Creates new form NewJFrame
  20.      */
  21.     public NewJFrame() {
  22.         initComponents();
  23.     }
  24.  
  25.     /**
  26.      * This method is called from within the constructor to initialize the form.
  27.      * WARNING: Do NOT modify this code. The content of this method is always
  28.      * regenerated by the Form Editor.
  29.      */
  30.     @SuppressWarnings("unchecked")
  31.     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  32.     private void initComponents() {
  33.  
  34.         jButton1 = new javax.swing.JButton();
  35.         jScrollPane1 = new javax.swing.JScrollPane();
  36.         jTextArea1 = new javax.swing.JTextArea();
  37.         jPanel1 = new javax.swing.JPanel();
  38.  
  39.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  40.  
  41.         jButton1.setText("Megnyit");
  42.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  43.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  44.                 jButton1ActionPerformed(evt);
  45.             }
  46.         });
  47.  
  48.         jTextArea1.setColumns(20);
  49.         jTextArea1.setRows(5);
  50.         jScrollPane1.setViewportView(jTextArea1);
  51.  
  52.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  53.         jPanel1.setLayout(jPanel1Layout);
  54.         jPanel1Layout.setHorizontalGroup(
  55.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  56.             .addGap(0, 610, Short.MAX_VALUE)
  57.         );
  58.         jPanel1Layout.setVerticalGroup(
  59.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  60.             .addGap(0, 0, Short.MAX_VALUE)
  61.         );
  62.  
  63.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  64.         getContentPane().setLayout(layout);
  65.         layout.setHorizontalGroup(
  66.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  67.             .addGroup(layout.createSequentialGroup()
  68.                 .addContainerGap()
  69.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  70.                     .addGroup(layout.createSequentialGroup()
  71.                         .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE)
  72.                         .addGap(18, 18, 18)
  73.                         .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  74.                     .addGroup(layout.createSequentialGroup()
  75.                         .addComponent(jButton1)
  76.                         .addGap(0, 0, Short.MAX_VALUE)))
  77.                 .addContainerGap())
  78.         );
  79.         layout.setVerticalGroup(
  80.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  81.             .addGroup(layout.createSequentialGroup()
  82.                 .addContainerGap()
  83.                 .addComponent(jButton1)
  84.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  85.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  86.                     .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  87.                     .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE))
  88.                 .addContainerGap())
  89.         );
  90.  
  91.         pack();
  92.     }// </editor-fold>//GEN-END:initComponents
  93.  
  94.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  95.         FileInputStream fstream_kv = null;
  96.         try {
  97.             JFileChooser fc = new JFileChooser("U:\\Koroknai Viktor\\Esemenyvezérelt_programozás\\1015ked0810ba02");
  98.             fc.showOpenDialog(null);
  99.             String utvonal = fc.getSelectedFile().getPath();
  100.             int kit_kv=0;
  101.             for (int kv = utvonal.length()-1; kv >0; kv--) {
  102.                 if (utvonal.charAt(kv) == '.'){
  103.                     kit_kv = kv;
  104.                     break;
  105.                 }
  106.             }
  107.             String kiterjesztes = fc.getSelectedFile().getPath().substring(kit_kv+1);
  108.             fstream_kv = new FileInputStream(utvonal);
  109.             if (kiterjesztes.compareTo("TXT") == 0){
  110.                 jTextArea1.setEnabled(true);
  111.                 jPanel1.setEnabled(false);
  112.                 jTextArea1.setText(utvonal +"  és ennek tartalma: ");
  113.                 DataInputStream in = new DataInputStream(fstream_kv);
  114.                 BufferedReader br = new BufferedReader(new InputStreamReader(in, "Cp1250"));
  115.                 String n="";
  116.                 while ((n = br.readLine()) != null) {
  117.                     jTextArea1.append("\n" + n);
  118.  
  119.                 } //whilolv
  120.                 jTextArea1.setCaretPosition(0);
  121.                 in.close();
  122.                
  123.             }
  124.             else {
  125.                 try {
  126.                     jTextArea1.setEnabled(false);
  127.                     jPanel1.setEnabled(true);
  128.                     utvonal.replace('\\', '/');
  129.                     ImageIcon xx = new ImageIcon(utvonal);
  130.                     Graphics g = jPanel1.getGraphics();
  131.                     g.drawImage(xx.getImage(),0,0,500,400,null);
  132.                 } catch (Exception e) {
  133.                 }
  134.             }
  135.            
  136.         } catch (FileNotFoundException ex) {
  137.             Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
  138.         } catch (UnsupportedEncodingException ex) {
  139.             Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
  140.         } catch (IOException ex) {
  141.             Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
  142.         } finally {
  143.             try {
  144.                 fstream_kv.close();
  145.             } catch (IOException ex) {
  146.                 Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
  147.             }
  148.         }
  149.     }//GEN-LAST:event_jButton1ActionPerformed
  150.  
  151.     /**
  152.      * @param args the command line arguments
  153.      */
  154.     public static void main(String args[]) {
  155.         /* Set the Nimbus look and feel */
  156.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  157.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  158.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  159.          */
  160.         try {
  161.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  162.                 if ("Nimbus".equals(info.getName())) {
  163.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  164.                     break;
  165.                 }
  166.             }
  167.         } catch (ClassNotFoundException ex) {
  168.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  169.         } catch (InstantiationException ex) {
  170.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  171.         } catch (IllegalAccessException ex) {
  172.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  173.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  174.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  175.         }
  176.         //</editor-fold>
  177.  
  178.         /* Create and display the form */
  179.         java.awt.EventQueue.invokeLater(new Runnable() {
  180.             public void run() {
  181.                 new NewJFrame().setVisible(true);
  182.             }
  183.         });
  184.     }
  185.  
  186.     // Variables declaration - do not modify//GEN-BEGIN:variables
  187.     private javax.swing.JButton jButton1;
  188.     private javax.swing.JPanel jPanel1;
  189.     private javax.swing.JScrollPane jScrollPane1;
  190.     private javax.swing.JTextArea jTextArea1;
  191.     // End of variables declaration//GEN-END:variables
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement