2016-10-31 3 views
-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); 


      } 
    });