|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Oct 2001
Messaggi: 345
|
Due domande per java
1) Esiste un metodo predefinito di java che permette di memorizzare in una variabile di tipo int un'intero acquisito da tastiera senza che questo venga visualizzato sullo schermo?
2) supponiamo che io debba aquisire un numero e per sbaglio inserisco una stringa, come posso fare in modo che mi richieda di inserire il numero? GRAZIE A CIUNQUE POSSA AIUTARMI! |
|
|
|
|
|
#2 |
|
Bannato
Iscritto dal: Nov 2001
Città: Verona
Messaggi: 1086
|
1) no
2) puoi effettuare una conversione a numero della stringa inserita intercettando l'eccezione NumberFormatException (nome eloquente, appare quando l'utente ha un'idea tutta sua del concetto di "numero" Ciao. |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Oct 2001
Messaggi: 345
|
esiste qualche modo per risolvere lo stesso il primo problema?
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Oct 2001
Messaggi: 345
|
E se invece volessi far acquisire un carattere senza acquisirlo? Lo posso fare?
|
|
|
|
|
|
#5 | |
|
Senior Member
Iscritto dal: Jan 2002
Città: Spagna
Messaggi: 556
|
Quote:
e se io volessi fare un programma senza farlo? |
|
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Oct 2001
Messaggi: 345
|
Volevo dire senza visualizzarlo.......
|
|
|
|
|
|
#7 | |
|
Bannato
Iscritto dal: May 2003
Città: Roma
Messaggi: 3642
|
Quote:
|
|
|
|
|
|
|
#8 |
|
Senior Member
Iscritto dal: Oct 2001
Messaggi: 345
|
Non ho capito pressocchè nulla della risposta!
|
|
|
|
|
|
#9 | |
|
Bannato
Iscritto dal: May 2003
Città: Roma
Messaggi: 3642
|
Quote:
quella roba li |
|
|
|
|
|
|
#10 | |
|
Senior Member
Iscritto dal: Apr 2002
Città: Vigevano(PV)
Messaggi: 2124
|
Quote:
cosa non ti è chiaro?
__________________
Gnu/Linux User
|
|
|
|
|
|
|
#11 | |
|
Bannato
Iscritto dal: May 2003
Città: Roma
Messaggi: 3642
|
Quote:
Codice:
//File Frame1.java, da compilare ed eseguire normalmente ;)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Frame1 extends JFrame {
JPasswordField jPasswordField1 = new JPasswordField();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
public Frame1() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Frame1 frame1 = new Frame1();
frame1.show();
}
private void jbInit() throws Exception {
this.setSize(new Dimension(444, 388));
this.addWindowListener(new Frame1_this_windowAdapter(this));
jPasswordField1.setText("");
jPasswordField1.setBounds(new Rectangle(88, 65, 177, 35));
jPasswordField1.addKeyListener(new Frame1_jPasswordField1_keyAdapter(this));
this.getContentPane().setLayout(null);
jLabel1.setText("");
jLabel1.setBounds(new Rectangle(84, 161, 212, 19));
jLabel2.setText("Istro:digita nel campo JPassword e leggi sotto quello che scrivi");
jLabel2.setBounds(new Rectangle(25, 326, 443, 24));
this.getContentPane().add(jPasswordField1, null);
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(jLabel2, null);
}
void jPasswordField1_keyTyped(KeyEvent e) {
if (e.getKeyChar()=='\b' && ! jLabel1.getText().equals(""))
jLabel1.setText(jLabel1.getText().substring(0,jLabel1.getText().length()-1));
else
jLabel1.setText(jLabel1.getText()+e.getKeyChar());
}
void this_windowDeactivated(WindowEvent e) {
System.exit(1);
}
}
class Frame1_jPasswordField1_keyAdapter extends java.awt.event.KeyAdapter {
Frame1 adaptee;
Frame1_jPasswordField1_keyAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void keyTyped(KeyEvent e) {
adaptee.jPasswordField1_keyTyped(e);
}
}
class Frame1_this_windowAdapter extends java.awt.event.WindowAdapter {
Frame1 adaptee;
Frame1_this_windowAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void windowClosing(WindowEvent e) {
adaptee.this_windowDeactivated(e);
}
}
|
|
|
|
|
|
|
#12 |
|
Senior Member
Iscritto dal: Oct 2001
Messaggi: 345
|
Ti ringrazio moltissimo ma io speravo in qualcosa di più semplice (io sto appena cominciando!). Non lo so qualcosa come il metodo getch del c++!
GRAZIE MILLE |
|
|
|
|
|
#13 | |
|
Bannato
Iscritto dal: May 2003
Città: Roma
Messaggi: 3642
|
Quote:
|
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 09:45.



















