Advertisement
Guest User

kb

a guest
Oct 15th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.47 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.             if (kiterjesztes.compareTo("TXT") == 0){
  109.                 jTextArea1.setEnabled(true);
  110.                 jPanel1.setEnabled(false);
  111.                 jTextArea1.setText(utvonal +"  és ennek tartalma: ");
  112.                 fstream_kv = new FileInputStream(utvonal);
  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.                     fstream_kv = new FileInputStream(utvonal);
  129.                     utvonal.replace('\\', '/');
  130.                     ImageIcon xx = new ImageIcon(utvonal);
  131.                     Graphics g = jPanel1.getGraphics();
  132.                     g.drawImage(xx.getImage(),0,0,500,400,null);
  133.                 } catch (Exception e) {
  134.                 }
  135.             }
  136.            
  137.         } catch (FileNotFoundException ex) {
  138.             Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
  139.         } catch (UnsupportedEncodingException ex) {
  140.             Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
  141.         } catch (IOException ex) {
  142.             Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
  143.         } finally {
  144.             try {
  145.                 fstream_kv.close();
  146.             } catch (IOException ex) {
  147.                 Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
  148.             }
  149.         }
  150.     }//GEN-LAST:event_jButton1ActionPerformed
  151.  
  152.     /**
  153.      * @param args the command line arguments
  154.      */
  155.     public static void main(String args[]) {
  156.         /* Set the Nimbus look and feel */
  157.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  158.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  159.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  160.          */
  161.         try {
  162.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  163.                 if ("Nimbus".equals(info.getName())) {
  164.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  165.                     break;
  166.                 }
  167.             }
  168.         } catch (ClassNotFoundException ex) {
  169.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  170.         } catch (InstantiationException ex) {
  171.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  172.         } catch (IllegalAccessException ex) {
  173.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  174.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  175.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  176.         }
  177.         //</editor-fold>
  178.  
  179.         /* Create and display the form */
  180.         java.awt.EventQueue.invokeLater(new Runnable() {
  181.             public void run() {
  182.                 new NewJFrame().setVisible(true);
  183.             }
  184.         });
  185.     }
  186.  
  187.     // Variables declaration - do not modify//GEN-BEGIN:variables
  188.     private javax.swing.JButton jButton1;
  189.     private javax.swing.JPanel jPanel1;
  190.     private javax.swing.JScrollPane jScrollPane1;
  191.     private javax.swing.JTextArea jTextArea1;
  192.     // End of variables declaration//GEN-END:variables
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement