2016-10-31 19 views
-1

こんにちは! 私は現在、自分のシフトが終わったときに教えてくれる基本的なタイマーと同様に、別のタスク(それらの生産性を高めるものの1つ)を行うために20分ごとに覚え書きとして機能するはずのパーソナルプログラムに取り組んでいます。作業。 適切なテキストフィールドをint型に解析して、作成中のタイマー(およびプロファイルオブジェクト)に配置するのが難しいです。 私は私があなたの考えをお聞かせくださいこのについて移動するカップルの方法は、おそらくそこにいることを知っている、ここに私のコードは、これまでのところです:javafxでアラームを割り当てようとしています

package javafxneoalarm; 

import java.util.Timer; 
import java.util.TimerTask; 
import javafx.application.Application; 
import javafx.event.ActionEvent; 
import javafx.event.EventHandler; 
import javafx.geometry.Insets; 
import javafx.geometry.Pos; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.control.Label; 
import javafx.scene.control.TextField; 
import javafx.scene.layout.GridPane; 
import javafx.scene.layout.HBox; 
import javafx.scene.layout.StackPane; 
import javafx.scene.paint.Color; 
import javafx.scene.text.Font; 
import javafx.scene.text.FontWeight; 
import javafx.scene.text.Text; 
import javafx.stage.Stage; 

/** 
* 
* @author Hvd 
*/ 
public class JavaFXNeoAlarm extends Application { 

    @Override 
    public void start(Stage primaryStage) { 
     primaryStage.setTitle("Neo Alarm"); 
     GridPane grid = new GridPane(); 
     grid.setAlignment(Pos.CENTER); 
     grid.setHgap(10); 
     grid.setVgap(10); 
     grid.setPadding(new Insets(25, 25, 25, 25)); 

     Text sceneTitle = new Text("Welcome! \nPlease Enter Name &\nThe Hour/Minute of your Alarm"); 
     sceneTitle.setFont(Font.font("Helvetica", FontWeight.NORMAL, 20)); 
     grid.add(sceneTitle, 0, 0, 2, 1); 

     Button btn = new Button("Lets go!"); 
     HBox hbBtn = new HBox(10); 
     hbBtn.setAlignment(Pos.BOTTOM_RIGHT); 
     hbBtn.getChildren().add(btn); 
     grid.add(hbBtn, 1, 4); 

     final Text actiontarget = new Text(); 
       grid.add(actiontarget, 1, 6); 

     btn.setOnAction(new EventHandler<ActionEvent>() { 
      @Override 
      public void handle(ActionEvent e){ 
       actiontarget.setFill(Color.FIREBRICK); 
       actiontarget.setText("Count-down initiated \nMay the force be with you"); 
      } 
     }); 

     Label userName = new Label("Name: \n"); 
     grid.add(userName, 0, 1); 

     TextField userTextField = new TextField(); 
     grid.add(userTextField, 1, 1); 

     Label a1 = new Label("Alarm1: \n"); 
     grid.add(a1, 0, 2); 

     TextField a1BoxHr = new TextField(); 
     grid.add(a1BoxHr, 1, 2); 


     TextField a1BoxMin = new TextField(); 
     grid.add(a1BoxMin, 2, 2); 

     Label a2 = new Label("Alarm2: \n"); 
     grid.add(a2, 0, 3); 

     TextField a2BoxHr = new TextField(); 
     grid.add(a2BoxHr, 1, 3); 

     TextField a2BoxMin = new TextField(); 
     grid.add(a2BoxMin, 2, 3); 





     Scene scene = new Scene(grid, 300, 275); 
     primaryStage.setScene(scene); 
     primaryStage.show(); 


     // double 1BoxHr = Double.parseDouble(a1BoxHr); 
     // profileOne = new Profile(userTextField, (((a1BoxHr*60)+a1BoxMin)*60), (((a2BoxHr*60)+a2BoxMin)*60)); 

    } 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) { 
     launch(args); 

     Timer alarmA1 = new Timer(); 
     Timer alarmA2 = new Timer(); 

     TimerTask task = new TimerTask() 
     { 
      public void run(){ 
       // when timer goes off 
      } 
     }; 
     Profile profileOne; 


    } 

} 

とプロファイルクラス:だから、基本的にはどのように行う

package javafxneoalarm; 

/** 
* 
* @author Hvd 
*/ 
public class Profile { 
// declare instance variables 
    private String user; 
    private double alarm1; 
    private double alarm2; 

    // constructor (overloaded, has new instance variable or parameter to apply maths through) 

    public Profile(String newUser, double newAlarm1, double newAlarm2){ 
     user = newUser; 

     alarm1 = newAlarm1; 

     alarm2 = newAlarm2; 
    } 

    // getters 

    public String getUser(){ 
     return user; 
    } 

    public double getAlarm1(){ 
     return alarm1; 
    } 
    public double getAlarm2(){ 
     return alarm2; 
    } 

    // setters 

    public void setUser(String newUser){ 
     user = newUser; 
    } 

    public void setAlarm1(double newAlarm1){ 
     alarm1 = newAlarm1; 
    } 

    public void setAlarm2(double newAlarm2){ 
     alarm2 = newAlarm2; 
    } 




} 

xの時間が経過した後に消えるアラームに入力を割り当てます。また、プロファイル情報の入力/送信後にウィンドウを閉じる/最小化したいのですが、アラームが鳴ったときに再オープンしますが、別の日に挑戦する。私はこの創造的な努力を続けることを楽しみにして

おかげでたくさんの男、:)

答えて

0

は、ここで私は、ボタンのクリック内の割り当てを配置する必要があり、テキストフィールドに入力に応じて、ダブルを割り当てる方法は次のとおりです。

btn.setOnAction(new EventHandler<ActionEvent>() { 
     @Override 
     public void handle(ActionEvent e){ 
      actiontarget.setFill(Color.FIREBRICK); 
      actiontarget.setText("Count-down initiated \nMay the force be with you"); 

      String BUser = userTextField.getText(); // sets variable BUser from inputs 

      double BAlarm1Hrs = Double.parseDouble(a1BoxHr.getText()); 
      double BAlarm1Min = Double.parseDouble(a1BoxMin.getText()); 
      double BAlarm1 = (((BAlarm1Hrs * 60) * 60) + (BAlarm1Min * 60)); // sets BAlarm1 to seconds of hrs and minutes inputted 


      double BAlarm2Hrs = Double.parseDouble(a2BoxHr.getText()); 
      double BAlarm2Min = Double.parseDouble(a2BoxMin.getText()); 
      double BAlarm2 = (((BAlarm2Hrs * 60) * 60) + (BAlarm2Min * 60)); 


      Profile profileA = new Profile(BUser, BAlarm1, BAlarm2); 


      } 
    }); 
関連する問題