Advertisement
RazorBlade57

lab

Mar 19th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1.  
  2. import java.awt.event.ActionEvent;
  3.  
  4. import javafx.application.Application;
  5. import javafx.event.EventHandler;
  6. import javafx.geometry.Insets;
  7. import javafx.scene.Scene;
  8. import javafx.scene.control.Button;
  9. import javafx.scene.control.TextField;
  10. import javafx.scene.layout.*;
  11. import javafx.stage.Stage;
  12.  
  13. public class CellPhone extends Application implements EventHandler<ActionEvent> {
  14.  
  15. private Button keyPad[] = new Button[12];
  16. private TextField phone = new TextField();
  17.  
  18. public void handle(ActionEvent e) {
  19. Button bt = (Button)e.getSource();
  20. String phone_entered = phone.getText();
  21. String newValue = phone_entered + bt.getText();
  22. phone.setText(newValue);
  23. }
  24.  
  25. public static void main(String[] args) {
  26. // TODO Auto-generated method stub
  27. Application.launch(args);
  28.  
  29. }
  30.  
  31. @Override
  32. public void start(Stage primarystage){
  33.  
  34. phone.setPrefColumnCount(10);
  35.  
  36. GridPane phonePad = new GridPane();
  37. phonePad.setPadding(new Insets (5,5,5,5));
  38.  
  39. phonePad.setHgap(15);
  40. phonePad.setVgap(15);
  41.  
  42. int k, row, col;
  43.  
  44. for(k=1, row = 0; row < 3; row++) {
  45. for (col = 0; col<3; col++,k++) {
  46. keyPad[k] = new Button(""+k);
  47. phonePad.add(keyPad[k], col, row);
  48.  
  49. }
  50. }
  51.  
  52. keyPad[10] = new Button("*");
  53. keyPad[11] = new Button("#");
  54. keyPad[0] = new Button("0");
  55.  
  56. phonePad.add(keyPad[10], 0, 3);
  57. phonePad.add(keyPad[0], 1, 3);
  58. phonePad.add(keyPad[11],2 , 3);
  59.  
  60. for(k=0; k<keyPad.length;k++) {
  61. keyPad[k].setOnAction(this);
  62. }
  63.  
  64. //create a border pane
  65. BorderPane pane = new BorderPane();
  66. pane.setCenter(phonePad);
  67. pane.setTop(phone);
  68.  
  69. Scene scene = new Scene(pane, 80,180);
  70. primarystage.setTitle("Call");
  71. primarystage.setScene(scene);
  72. primarystage.show();
  73.  
  74. }
  75.  
  76. }
  77. /////////////////////////////////////////////////////////
  78.  
  79. Lab 6 pg 621 #15.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement