始める前は、私は初心者プログラマーです。
ボタンがクリックされたときにテキスト フィールドを有効にするにはどうすればよいですか。
私は 2 つのフレームを持っています。1 つは JFields を持ち、もう 1 つは例外用です。例外が発生した場合 > setEditable(false) しかし、ユーザーが [OK] ボタンをクリックしたときに JFields を有効にするには、どのステートメントを作成する必要がありますか?例外で作成したものですか?
静的ブール値を例外フレームに追加しようとしましたが、このクラスで実行されるアクション内で、そのブール値をtrueに初期化しました。
他のクラスでは、if ステートメントを追加しました。そのブール値が true の場合、setEditable(true)
-========- このプログラムのポイントは、例外が発生すると、ユーザーは例外ウィンドウを閉じるまでフィールドに何も入力できないことです。
あなたが私を助けてくれたらいいのに。
愛を込めて、プログラマー。
THE EXCEPTION WINDOW FRAME (Okay ボタンがある) に対して実行されるアクションのコード。
public void actionPerformed(ActionEvent e){
{
allow=true; //static boolean
Container TheFrame = OKButton.getParent();
do TheFrame = TheFrame.getParent();
while (!(TheFrame instanceof JFrame));
((JFrame) TheFrame).dispose();
}
THE MAIN PROGRAM に対して実行されるアクションのコード (3 つのフィールドがあり、ユーザーが数字以外を入力すると例外が発生します) 明確にするためにいくつかのコメントを追加しました。
public void actionPerformed(ActionEvent event) {
try{
r =Double.parseDouble(RField.getText());
s=Double.parseDouble(SField.getText());
h=Double.parseDouble(HField.getText());
Cone C = new Cone(r,s,h);//class cone
if (event.getSource() instanceof JButton) {
JButton clickedButton = (JButton) event.getSource();
if (clickedButton == VolumeButton) {
Result.append("VOLUME = "+C.volume()+ "\n");
ifV= true;//this's for clearing the fields for new entries.
}
if (clickedButton == AreaButton) {
Result.append("SURFACE AREA = "+C.surfaceArea()+ "\n");
ifA= true;//this's for clearing the fields for new entries.
}
if(ifA&&ifV){ // clearing the fields for new entries.
SField.setText(CLEAR);
HField.setText(CLEAR);
RField.setText(CLEAR);
ifV=false; ifA= false;}
}
SList.addShape(C);
}
catch(NumberFormatException e){
//Object of type "Exception__" already created
Ex.setVisible(true);//class "Exception__" is the one i've made for Exception window
SField.setText(CLEAR);
HField.setText(CLEAR);
RField.setText(CLEAR);
SField.setEditable(false);
HField.setEditable(false);
RField.setEditable(false);
}/*here, if the user clicked on -that okay in Exception window-
and variable allow initialized to "true" those statements should extend. I guess?
- everything worked correctly except for this ?*/
if(Ex.allow){
SField.setEditable(true);
HField.setEditable(true);
RField.setEditable(true); }
}
最終的に機能したすべてに感謝します。
追加した
Ex.allow(SField,HField,RField);
キャッチに。
このメソッドをクラス Exception__ に追加しました。
public void allow(JTextField js,JTextField jh,JTextField jr){
HField =jh;
SField =js;
RField =jr;
}
最後に、クラス Exception__ で実行されるアクションに:
SField.setEditable(true);
HField.setEditable(true);
RField.setEditable(true);
うおおお。すごい感じです笑。皆さんありがとう。私の質問を削除するか、私と同じ問題に直面する可能性のある他の人に任せるべきですか? :P