HI again! Thanks for all the help!
I need help again , please
How can i paint inside the grid, like , make all black;
Heres my Two Classes, the css file and the java class. Please help
package musica;
import java.io.File;
import javafx.application.Application;
import javafx.beans.property.ObjectProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaErrorEvent;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.util.Duration;
import javax.swing.Action;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javax.swing.JTextField;
import javafx.scene.paint.*;
/**
*
* @author André Lopes
*/
public class Musica extends Application {
public MediaPlayer MP;
public Media Media;
public static String MusicURL;
public static JFileChooser JFC;
public static Duration currentTime;
public MediaView mediaView;
public static WebView view;
public static WebEngine webEng;
public static TextField webFieldURL;
private static String webUrl;
private void init(Stage primaryStage) {
view = new WebView();
view.setMaxSize(1000,1000);
view.setMinSize(950,700);
webEng = view.getEngine();
webEng.load("http://www.google.com.br");
System.out.println("Web Engine Started!");
}
public Musica()
{
webUrl = "www.google.com.br";
webFieldURL = new TextField(webUrl);
currentTime = Duration.ZERO;
mediaView= new MediaView(MP);
MusicURL = "";
//URL = "http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv";
}
//////////////////////////////////////////////////////////////
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello! This is Yours Music Player!");
//Carrega A Web-Objects!
init(primaryStage);
//Botão Play
Button Play = new Button();
Play.setText("Play");
Play.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event1) {
Media = new Media(MusicURL);
MP = new MediaPlayer(Media);
MP.setStartTime(currentTime);
mediaView.setMediaPlayer(MP);
MP.play();
System.out.println("MediaPlayerStatus: "+ MP.getStatus());
mediaView.setOnError(new EventHandler<MediaErrorEvent>() {
@Override
public void handle(MediaErrorEvent arg0) {
System.out.println("MediaErrorEvent-arg0: " + MP.getStatus());
}
});
}
});
//Botão para Entrar No site Digitado
Button SendWebUrl = new Button();
SendWebUrl.setVisible(true);
SendWebUrl.setText("Send");
SendWebUrl.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
webUrl = webFieldURL.getText();
EnterWebSite(webUrl);
}
});
//Botão pra escolher Musica
Button SelctFileButton = new Button();
SelctFileButton.setText("Music Chooser/Finder:");
SelctFileButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
System.out.println("Java File Chooser Opened");
JFileChooser search = new JFileChooser();
search.showDialog(search,null);
MusicURL = search.getSelectedFile().toURI().toString();
System.out.println("File URL: "+MusicURL);
}
});
//Botão para pausar;
Button Pause = new Button();
Pause.setText("Pause");
Pause.setFont(Font.font(null, FontPosture.ITALIC,15));
Pause.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
try {
currentTime = MP.getCurrentTime();
MP.pause();
}catch(java.lang.NullPointerException e)
{
System.out.println("java.lang.NullPointerException \n");
System.out.println("Error: Unable To pause! May happens if you didnt have a music Playing!");
}
}
});
//Botão Para Continuar;
Button Continue = new Button();
Continue.setText("Continue/UnPause");
Continue.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
//MP.setStartTime(currentTime);
MP.pause();
}
});
//Grid ! Layout
GridPane grid = new GridPane();
StackPane root = new StackPane();
grid.setHgap(2);
grid.setHgap(2);
grid.setVgap(2);
Scene Scene = new Scene(root,500,500);
Scene.getStylesheets().add(getClass().getResource("Cascade.css").toExternalForm());
grid.getStyleClass().add(getClass().getResource("Cascade.css").toExternalForm());
root.getStyleClass().add(getClass().getResource("Cascade.css").toExternalForm());
root.getChildren().add(grid);
primaryStage.setScene(Scene);
primaryStage.show();
//Adicionando Botoes no Grid (Grid.add(NODE,Column,Row);
grid.add(Play,1,3);
grid.add(Pause,2,3);
grid.add(SelctFileButton,1,4);
grid.add(view,10,10);
webFieldURL.appendText(" ");
grid.add(webFieldURL,10,8);
grid.add(SendWebUrl,9,8);
}
//Método para trocar de Site
public static void EnterWebSite(String WebUrl)
{
System.out.println("Entering A Website!");
webEng = view.getEngine();
webEng.load("http://" + WebUrl);
}
//Main
public static void main(String[] args) {
launch(args);
}
}
CSS:
/*
Document : Cascade
Created on : 07/05/2012, 22:01:28
Author : André
Description:
Purpose of the stylesheet follows.
*/
.root{
-fx-font-size: 14pt;
-fx-font-family: "Tahoma";
-fx-base: #DFB951;
-fx-background: #A78732;
-fx-focus-color: #B6A678;
}
GridPanel{
columns:500;
rows:500;
-fx-color:red;
-fx-background-color: red;
}
.grid {
-fx-color: black;
-fx-background-color: black;
}