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.
- */
- package texteditor;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- /**
- *
- * @author Guilherme
- */
- public class mainScreen extends javax.swing.JFrame {
- private static void setExtendedState() {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- /**
- * Creates new form mainScreen
- */
- public mainScreen() {
- initComponents();
- saveFile.setEnabled(false);
- closeFile.setEnabled(false);
- editorPane.setVisible(false);
- }
- /**
- * 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">
- private void initComponents() {
- panel = new javax.swing.JPanel();
- newFile = new javax.swing.JButton();
- openFile = new javax.swing.JButton();
- saveFile = new javax.swing.JButton();
- closeFile = new javax.swing.JButton();
- exit = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- editorPane = new javax.swing.JEditorPane();
- surpriseMotherfucker = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setLocation(new java.awt.Point(0, 0));
- newFile.setText("Novo");
- newFile.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- newFileActionPerformed(evt);
- }
- });
- openFile.setText("Abrir");
- openFile.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- openFileActionPerformed(evt);
- }
- });
- saveFile.setText("Salvar");
- saveFile.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- saveFileActionPerformed(evt);
- }
- });
- closeFile.setText("Fechar");
- closeFile.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- closeFileActionPerformed(evt);
- }
- });
- exit.setText("Finalizar");
- exit.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- exitActionPerformed(evt);
- }
- });
- editorPane.addKeyListener(new java.awt.event.KeyAdapter() {
- public void keyTyped(java.awt.event.KeyEvent evt) {
- editorPaneKeyTyped(evt);
- }
- });
- jScrollPane1.setViewportView(editorPane);
- surpriseMotherfucker.setText("jButton1");
- surpriseMotherfucker.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- surpriseMotherfuckerActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel);
- panel.setLayout(panelLayout);
- panelLayout.setHorizontalGroup(
- panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelLayout.createSequentialGroup()
- .addContainerGap()
- .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(panelLayout.createSequentialGroup()
- .addGap(0, 0, Short.MAX_VALUE)
- .addComponent(surpriseMotherfucker, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 634, Short.MAX_VALUE)
- .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelLayout.createSequentialGroup()
- .addComponent(newFile)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(openFile)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(saveFile)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(closeFile)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(exit)))
- .addGap(16, 16, 16))
- );
- panelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {closeFile, exit, newFile, openFile, saveFile});
- panelLayout.setVerticalGroup(
- panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(panelLayout.createSequentialGroup()
- .addGap(11, 11, 11)
- .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(newFile)
- .addComponent(openFile)
- .addComponent(saveFile)
- .addComponent(closeFile)
- .addComponent(exit))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
- .addComponent(surpriseMotherfucker, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE))
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- pack();
- setLocationRelativeTo(null);
- }// </editor-fold>
- File file = new File("C:/texto.txt");
- private void newFileActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- //String path = JOptionPane.showInputDialog("Digite o caminho onde deseja salvar o arquivo: ");
- try {
- file.createNewFile();
- System.out.println("Arquivo 'texto' criado com sucesso.");
- saveFile.setEnabled(true);
- System.out.println("Botão salvar ativado!");
- editorPane.setVisible(true);
- System.out.println("Editor de texto liberado");
- } catch (IOException ex) {
- Logger.getLogger(mainScreen.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void openFileActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- // TODO add your handling code here:
- FileReader fr = new FileReader(file);
- BufferedReader br = new BufferedReader(fr);
- newFile.setEnabled(false);
- System.out.println("Botão novo desativado!");
- saveFile.setEnabled(true);
- System.out.println("Botão salvar ativado!");
- closeFile.setEnabled(true);
- System.out.println("Botão fechar ativado!");
- editorPane.setVisible(true);
- System.out.println("Editor de texto liberado!");
- while(br.ready())
- {
- String line = br.readLine();
- editorPane.setText(line);
- }
- br.close();
- fr.close();
- } catch (FileNotFoundException ex) {
- Logger.getLogger(mainScreen.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(mainScreen.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void saveFileActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- FileWriter fw = new FileWriter(file);
- BufferedWriter bw = new BufferedWriter(fw);
- bw.write(editorPane.getText());
- bw.close();
- System.out.println("Texto salvo com sucesso!(Teoricamente :D)");
- JOptionPane.showMessageDialog(null, "Arquivo salvo com sucesso!");
- closeFile.setEnabled(true);
- System.out.println("Botão fechar ativado!");
- } catch (IOException ex) {
- Logger.getLogger(mainScreen.class.getName()).log(Level.SEVERE, null, ex);
- }
- closeFile.setEnabled(true);
- System.out.println("Botão fechar ativado!");
- }
- private void closeFileActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- try {
- FileWriter fw = new FileWriter(file);
- BufferedWriter bw = new BufferedWriter(fw);
- bw.write(editorPane.getText());
- bw.close();
- System.out.println("Texto salvo com sucesso!(Teoricamente :D)");
- JOptionPane.showMessageDialog(null, "Arquivo salvo com sucesso!");
- saveFile.setEnabled(false);
- System.out.println("Botão salvar desativado!");
- closeFile.setEnabled(false);
- System.out.println("Botão fechar desativado!");
- } catch (IOException ex) {
- Logger.getLogger(mainScreen.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void exitActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- dispose();
- }
- private void editorPaneKeyTyped(java.awt.event.KeyEvent evt) {
- // TODO add your handling code here:
- String text = editorPane.getText();
- System.out.println("Testo sendo digitado: "+text);
- }
- private void surpriseMotherfuckerActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- JOptionPane.showMessageDialog(null, "Esse botão aqui foi feito pra você curioso que "
- + "não sabe o que o botão faz e já vai apertando.\n"
- + " Se não fosse por minha boa natureza agora "
- + "você teria cagado todo software.\n\n"
- + "Guilherme Ramalho");
- }
- /**
- * @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 ("Metal".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(mainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(mainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(mainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(mainScreen.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 mainScreen().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton closeFile;
- private javax.swing.JEditorPane editorPane;
- private javax.swing.JButton exit;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JButton newFile;
- private javax.swing.JButton openFile;
- private javax.swing.JPanel panel;
- private javax.swing.JButton saveFile;
- private javax.swing.JButton surpriseMotherfucker;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment