Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

++ close and move GUI #12

Merged
merged 1 commit into from
Dec 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/project/Controller.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
package project;

public class Controller {
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.Label;

import javafx.event.ActionEvent;
import javafx.scene.input.MouseEvent;

public class Controller implements EventHandler<ActionEvent>{

@FXML
private Label exit;

@FXML
private void handleClose(MouseEvent event) {
if(event.getSource()== exit)
{
System.exit(0);
}
}
public void handle(ActionEvent event){

}


}
76 changes: 27 additions & 49 deletions src/project/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ public Main(){


import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.stage.*;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
Expand All @@ -36,64 +38,40 @@ public Main(){
import javafx.geometry.Pos;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;



public class Main extends Application {

Stage window;
Scene scene1, scene2;
BorderPane layout;
private double xOffset = 0;
private double yOffset = 0;

@Override
public void start(Stage primaryStage) throws Exception{
window = primaryStage;
public void start(Stage stage) throws Exception{

Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));

// bp.setTop(x=new Label("Air"));
// x.setAlignment(Pos.CENTER);
// x.setBackground(new Background(new BackgroundFill(Color.BISQUE,
// new CornerRadii(4),new Insets(3))));
// x.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
// x.setPrefHeight(50);


//Search Menu
Menu searchMenu = new Menu("_search");

//Menu Items
MenuItem newFile = new MenuItem("New");
newFile.setOnAction(e -> System.out.println("Create a new file"));
searchMenu.getItems().add(newFile);
searchMenu.getItems().add(new MenuItem("Actor"));
searchMenu.getItems().add(new SeparatorMenuItem());
searchMenu.getItems().add(new MenuItem("Movie"));
searchMenu.getItems().add(new SeparatorMenuItem());
searchMenu.getItems().add(new MenuItem("Exit"));


//Main menu bar
MenuBar menuBar = new MenuBar();
menuBar.getMenus().addAll(searchMenu);

layout = new BorderPane();
layout.setTop(menuBar);

//button 1
Label label1 = new Label("Welcome to the first scene!");
Button button1 = new Button("Go to scene 2");
button1.setOnAction(e -> window.setScene(scene2));

//layout 1
VBox layout1 = new VBox(20);
layout1.getChildren().addAll(label1,button1);
Scene scene1 = new Scene(layout, 400,400);


window.setScene(scene1);
window.setTitle("Better IMDB");
window.show();
stage.initStyle(StageStyle.UNDECORATED);
root.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
xOffset = event.getSceneX();
yOffset = event.getSceneY();
}
});

root.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
stage.setX(event.getScreenX() - xOffset);
stage.setY(event.getScreenY() - yOffset);
}
});

Scene scene1 = new Scene(root);

stage.setScene(scene1);
stage.show();
}


Expand Down
19 changes: 12 additions & 7 deletions src/project/sample.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="700.0" style="-fx-background-color: #20121f;" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="700.0" style="-fx-background-color: #20121f;" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="project.Controller">
<children>
<AnchorPane layoutX="350.0" layoutY="23.0" prefHeight="348.0" prefWidth="318.0" style="-fx-background-color: #9c2b26;">
<AnchorPane layoutX="364.0" layoutY="40.0" prefHeight="325.0" prefWidth="300.0" style="-fx-background-color: #9c2b2f;">
<children>
<ChoiceBox layoutX="84.0" layoutY="109.0" prefWidth="150.0" />
<TextField layoutX="41.0" layoutY="206.0" prefHeight="25.0" prefWidth="236.0" />
<Button layoutX="41.0" layoutY="276.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="236.0" text="Search" />
<Label alignment="CENTER" layoutX="104.0" layoutY="30.0" prefHeight="43.0" prefWidth="110.0" text="Search" textOverrun="CLIP">
<ChoiceBox layoutX="85.0" layoutY="109.0" prefWidth="150.0" />
<TextField alignment="CENTER" layoutX="40.0" layoutY="206.0" prefHeight="25.0" prefWidth="245.0" />
<Button alignment="CENTER" layoutX="40.0" layoutY="276.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="245.0" text="Search" />
<Label alignment="CENTER" layoutX="110.0" layoutY="30.0" prefHeight="45.0" prefWidth="110.0" text="Search" textOverrun="CLIP">
<font>
<Font size="32.0" />
</font>
</Label>
</children></AnchorPane>
<ListView layoutX="14.0" layoutY="28.0" prefHeight="348.0" prefWidth="318.0" />
<ListView layoutX="25.0" layoutY="40.0" prefHeight="325.0" prefWidth="300.0" style="-fx-background-color: #9c2b2f"/>
<Label fx:id="exit" layoutX="677.0" onMousePressed="#handleClose" prefHeight="35.0" prefWidth="18.0" text="X" textFill="#e52019dc">
<font>
<Font name="System Bold" size="25.0" />
</font>
</Label>
</children>
</AnchorPane>