java - Unable to right click on Jframe / JTextAreaNetBeans -
for reason, run code can't paste text in text areas. ideas?
enterpackage cesar; import java.io.file; import java.io.filenotfoundexception; import java.util.scanner; import java.util.logging.level; import java.util.logging.logger; /** * * @author sanikte */ public class newjframe extends javax.swing.jframe { cesar cifrado = new cesar(); /** * creates new form newjframe */ public newjframe() { initcomponents(); } /** * method called within constructor initialize form. * warning: not modify code. content of method * regenerated form editor. */ // <editor-fold defaultstate="collapsed" desc="generated code"> private void initcomponents() { jbutton2 = new javax.swing.jbutton(); jscrollpane2 = new javax.swing.jscrollpane(); jtextarea2 = new javax.swing.jtextarea(); label2 = new java.awt.label(); jbutton3 = new javax.swing.jbutton(); jscrollpane1 = new javax.swing.jscrollpane(); jtextarea1 = new javax.swing.jtextarea(); jbutton1 = new javax.swing.jbutton(); label1 = new java.awt.label(); setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close); jbutton2.settext("descifrar"); jbutton2.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton2actionperformed(evt); } }); jtextarea2.setcolumns(20); jtextarea2.setlinewrap(true); jtextarea2.setrows(5); jscrollpane2.setviewportview(jtextarea2); label2.settext("código cifrado"); jbutton3.settext("analizar"); jbutton3.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton3actionperformed(evt); } }); jtextarea1.setcolumns(20); jtextarea1.setrows(5); jscrollpane1.setviewportview(jtextarea1); jbutton1.settext("cifrar"); jbutton1.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton1actionperformed(evt); } }); label1.settext("código claro"); org.jdesktop.layout.grouplayout layout = new org.jdesktop.layout.grouplayout(getcontentpane()); getcontentpane().setlayout(layout); layout.sethorizontalgroup( layout.createparallelgroup(org.jdesktop.layout.grouplayout.leading) .add(org.jdesktop.layout.grouplayout.trailing, layout.createsequentialgroup() .add(85, 85, 85) .add(jscrollpane1, org.jdesktop.layout.grouplayout.preferred_size, 232, org.jdesktop.layout.grouplayout.preferred_size) .addpreferredgap(org.jdesktop.layout.layoutstyle.related, 108, short.max_value) .add(jscrollpane2, org.jdesktop.layout.grouplayout.preferred_size, org.jdesktop.layout.grouplayout.default_size, org.jdesktop.layout.grouplayout.preferred_size) .add(95, 95, 95)) .add(layout.createsequentialgroup() .add(153, 153, 153) .add(label1, org.jdesktop.layout.grouplayout.preferred_size, org.jdesktop.layout.grouplayout.default_size, org.jdesktop.layout.grouplayout.preferred_size) .add(304, 304, 304) .add(label2, org.jdesktop.layout.grouplayout.preferred_size, org.jdesktop.layout.grouplayout.default_size, org.jdesktop.layout.grouplayout.preferred_size) .addcontainergap(org.jdesktop.layout.grouplayout.default_size, short.max_value)) .add(layout.createsequentialgroup() .add(152, 152, 152) .add(jbutton1) .addpreferredgap(org.jdesktop.layout.layoutstyle.related, org.jdesktop.layout.grouplayout.default_size, short.max_value) .add(jbutton2) .add(149, 149, 149)) .add(org.jdesktop.layout.grouplayout.trailing, layout.createsequentialgroup() .addcontainergap(org.jdesktop.layout.grouplayout.default_size, short.max_value) .add(jbutton3) .add(321, 321, 321)) ); layout.setverticalgroup( layout.createparallelgroup(org.jdesktop.layout.grouplayout.leading) .add(layout.createsequentialgroup() .add(layout.createparallelgroup(org.jdesktop.layout.grouplayout.leading) .add(layout.createsequentialgroup() .add(42, 42, 42) .add(label2, org.jdesktop.layout.grouplayout.preferred_size, org.jdesktop.layout.grouplayout.default_size, org.jdesktop.layout.grouplayout.preferred_size)) .add(org.jdesktop.layout.grouplayout.trailing, layout.createsequentialgroup() .addcontainergap() .add(label1, org.jdesktop.layout.grouplayout.preferred_size, org.jdesktop.layout.grouplayout.default_size, org.jdesktop.layout.grouplayout.preferred_size))) .addpreferredgap(org.jdesktop.layout.layoutstyle.related) .add(layout.createparallelgroup(org.jdesktop.layout.grouplayout.leading) .add(layout.createsequentialgroup() .add(8, 8, 8) .add(jscrollpane1, org.jdesktop.layout.grouplayout.preferred_size, org.jdesktop.layout.grouplayout.default_size, org.jdesktop.layout.grouplayout.preferred_size) .add(18, 18, 18) .add(layout.createparallelgroup(org.jdesktop.layout.grouplayout.baseline) .add(jbutton1) .add(jbutton2)) .addcontainergap(org.jdesktop.layout.grouplayout.default_size, short.max_value)) .add(layout.createsequentialgroup() .add(jscrollpane2, org.jdesktop.layout.grouplayout.preferred_size, org.jdesktop.layout.grouplayout.default_size, org.jdesktop.layout.grouplayout.preferred_size) .addpreferredgap(org.jdesktop.layout.layoutstyle.related, 103, short.max_value) .add(jbutton3) .add(59, 59, 59)))) ); pack(); }// </editor-fold> private void jbutton1actionperformed(java.awt.event.actionevent evt) { try { // todo add handling code here: scanner diskscanner = new scanner(new file("/users/sanikte/desktop/key.txt")); //scanner diskscanner2 = new scanner(new file("/users/sanikte/desktop/texto.txt")); file file = new file("/users/sanikte/desktop/texto.txt"); scanner scanner = new scanner(file); int key = integer.parseint(diskscanner.next()); while (scanner.hasnextline()) { string texto = scanner.nextline(); jtextarea2.settext(cifrado.cifrar(texto, key)); } } catch (filenotfoundexception ex) { logger.getlogger(newjframe.class.getname()).log(level.severe, null, ex); } } private void jbutton2actionperformed(java.awt.event.actionevent evt) { try { // todo add handling code here: scanner diskscanner = new scanner(new file("/users/sanikte/desktop/key.txt")); int key = integer.parseint(diskscanner.next()); string texto = jtextarea2.gettext(); jtextarea1.settext(cifrado.descifrar(texto, key)); } catch (filenotfoundexception ex) { logger.getlogger(newjframe.class.getname()).log(level.severe, null, ex); } } private void jbutton3actionperformed(java.awt.event.actionevent evt) { // todo add handling code here: } /** * @param args command line arguments */ public static void main(string args[]) { /* set nimbus , feel */ //<editor-fold defaultstate="collapsed" desc=" , feel setting code (optional) "> /* if nimbus (introduced in java se 6) not available, stay default , feel. * details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { (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 , display form */ java.awt.eventqueue.invokelater(new runnable() { @override public void run() { new newjframe().setvisible(true); } }); } // variables declaration - not modify private javax.swing.jbutton jbutton1; private javax.swing.jbutton jbutton2; private javax.swing.jbutton jbutton3; private javax.swing.jscrollpane jscrollpane1; private javax.swing.jscrollpane jscrollpane2; private javax.swing.jtextarea jtextarea1; private javax.swing.jtextarea jtextarea2; private java.awt.label label1; private java.awt.label label2; // end of variables declaration }
like said, there no way right click when it's running, it's disabled , can't paste text i'm suppossed in there. ideas of why might happening?
make import:
import java.awt.event.mouseevent;
and then...
private void textfiledmousepressed(java.awt.event.mouseevent evt) { if (evt.getmodifiers() == mouseevent.button3_mask){ system.out.println("hey i'm using right click!"); } }
Comments
Post a Comment