Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- import java.awt.Graphics;
- import java.io.*;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.ImageIcon;
- import javax.swing.JFileChooser;
- /**
- *
- * @author labor
- */
- public class NewJFrame extends javax.swing.JFrame {
- /**
- * Creates new form NewJFrame
- */
- public NewJFrame() {
- 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.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
- private void initComponents() {
- jButton1 = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- jTextArea1 = new javax.swing.JTextArea();
- jPanel1 = new javax.swing.JPanel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jButton1.setText("Megnyit");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jTextArea1.setColumns(20);
- jTextArea1.setRows(5);
- jScrollPane1.setViewportView(jTextArea1);
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 610, Short.MAX_VALUE)
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 0, Short.MAX_VALUE)
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton1)
- .addGap(0, 0, Short.MAX_VALUE)))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jButton1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 504, Short.MAX_VALUE))
- .addContainerGap())
- );
- pack();
- }// </editor-fold>//GEN-END:initComponents
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
- FileInputStream fstream_kv = null;
- try {
- JFileChooser fc = new JFileChooser("U:\\Koroknai Viktor\\Esemenyvezérelt_programozás\\1015ked0810ba02");
- fc.showOpenDialog(null);
- String utvonal = fc.getSelectedFile().getPath();
- int kit_kv=0;
- for (int kv = utvonal.length()-1; kv >0; kv--) {
- if (utvonal.charAt(kv) == '.'){
- kit_kv = kv;
- break;
- }
- }
- String kiterjesztes = fc.getSelectedFile().getPath().substring(kit_kv+1);
- fstream_kv = new FileInputStream(utvonal);
- if (kiterjesztes.compareTo("TXT") == 0){
- jTextArea1.setEnabled(true);
- jPanel1.setEnabled(false);
- jTextArea1.setText(utvonal +" és ennek tartalma: ");
- DataInputStream in = new DataInputStream(fstream_kv);
- BufferedReader br = new BufferedReader(new InputStreamReader(in, "Cp1250"));
- String n="";
- while ((n = br.readLine()) != null) {
- jTextArea1.append("\n" + n);
- } //whilolv
- jTextArea1.setCaretPosition(0);
- in.close();
- }
- else {
- try {
- jTextArea1.setEnabled(false);
- jPanel1.setEnabled(true);
- utvonal.replace('\\', '/');
- ImageIcon xx = new ImageIcon(utvonal);
- Graphics g = jPanel1.getGraphics();
- g.drawImage(xx.getImage(),0,0,500,400,null);
- } catch (Exception e) {
- }
- }
- } catch (FileNotFoundException ex) {
- Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
- } catch (UnsupportedEncodingException ex) {
- Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
- } finally {
- try {
- fstream_kv.close();
- } catch (IOException ex) {
- Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }//GEN-LAST:event_jButton1ActionPerformed
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new NewJFrame().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton jButton1;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTextArea jTextArea1;
- // End of variables declaration//GEN-END:variables
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement