62,614
社区成员
发帖
与我相关
我的任务
分享
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Duration;
package hrms.controller;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class HrmsMainApp extends Application {
private Stage primaryStage;
private BorderPane rootLayout;
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("������Դ����ϵͳ");
initrootLayout();
}
public void initrootLayout() {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(HrmsMainApp.class.getResource("hrms.view/RootLayout.fxml"));
rootLayout = (BorderPane) loader.load();
// Show the scene containing the root layout.
Scene scene = new Scene(rootLayout);
primaryStage.setScene(scene);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
public Stage getPrimaryStage() {
return primaryStage;
}
public static void main(String[] args) {
launch(args);
}
}
还有RootLayout.fxml文件
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.effect.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.BorderPane?>
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1280.0" type="BorderPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<top>
<HBox alignment="BOTTOM_RIGHT" depthTest="ENABLE" prefHeight="80.0" prefWidth="1280.0" style="-fx-background-color: #336699;" BorderPane.alignment="CENTER">
<children>
<Button mnemonicParsing="false" text="Button">
<HBox.margin>
<Insets bottom="6.0" right="100.0" />
</HBox.margin>
</Button>
<Button contentDisplay="CENTER" mnemonicParsing="false" text="Button">
<HBox.margin>
<Insets bottom="6.0" right="100.0" />
</HBox.margin>
</Button>
</children></HBox>
</top>
<left>
<Accordion BorderPane.alignment="CENTER">
<panes>
<TitledPane animated="false" text="untitled 1">
<content>
<SplitPane prefHeight="200.0" prefWidth="200.0" />
</content>
<padding>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
</padding>
</TitledPane>
<TitledPane animated="false" text="untitled 2">
<content>
<SplitPane prefHeight="200.0" prefWidth="200.0" />
</content>
</TitledPane>
</panes>
</Accordion>
</left>
<bottom>
<HBox prefHeight="40.0" prefWidth="1280.0" BorderPane.alignment="CENTER" />
</bottom>
<center>
<Pane BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets bottom="3.0" left="3.0" top="3.0" />
</BorderPane.margin></Pane>
</center>
</fx:root>
重点是我做的哪里不对,主文件中19和26行怎么做才对?我是初学者,麻烦指点详细一点!!!
public static void main(String arg[]) {
fianal.launch(arg);
}
报的错误:
Exception in Application constructor
Exception in thread "main" java.lang.RuntimeException: Unable to construct Application instance: class fianal
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.access$000(Unknown Source)
at com.sun.javafx.application.LauncherImpl$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
... 4 more
Caused by: java.lang.ExceptionInInitializerError
at fianal.<init>(fianal.java:63)
... 8 more
Caused by: java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found
at javafx.scene.image.Image.validateUrl(Unknown Source)
at javafx.scene.image.Image.<init>(Unknown Source)
at Ball.<clinit>(Ball.java:16)
... 9 more
Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found
... 12 more
[/quote]
public class XXX extends Application{
...
}<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:fx="javafx:com.sun.javafx.tools.ant" default="main">
<!-- Import definition of JavaFX ant tasks, be attention to the path of JDK installed -->
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml" uri="javafx:com.sun.javafx.tools.ant"
classpath="/home/gaowen/jdk1.7.0_45/lib/ant-javafx.jar"/>
<property name="application.title" value="EnterprisePurchaseSellStockManagementSystem"/>
<property name="application.vendor" value="Gaowen HAN"/>
<property name="application.version" value="2.0"/>
<property name="src" value="src"/>
<property name="compile" value="bin"/>
<property name="dist" value="dist"/>
<property name="web" value="web"/>
<property name="javafx" value="${java.home}/lib/jfxrt.jar"/>
<property name="preloader" value="dist/lib/EnterprisePurchaseSellStockManagementSystemPreloader.jar"/>
<property name="derbynet" value="dist/lib/derbynet.jar"/>
<splash showduration="0" imageurl="file://${user.dir}/ant-splash.jpg"
displayText="${application.vendor}-${application.version}: Building..." progressRegExp="Progress: (.*)%"/>
<sound>
<success source="bell.wav" loops="0"/>
<fail source="ohno.wav" loops="0"/>
</sound>
<target name="init">
<echo message="I am target 'init'" level="info"/>
<mkdir dir="${compile}"/>
<javac srcdir="${src}" destdir="${compile}" includeAntRuntime="false"
classpath="${javafx}; ${preloader}; ${derbynet}"/>
<copy todir="${compile}">
<fileset dir="${src}" excludes="**/*.java"/>
</copy>
<fx:csstobin outdir="${compile}">
<fileset dir="${compile}" includes="**/*.css"/>
</fx:csstobin>
<!-- Details about application, as id cannot be the escaped string, we assign it by abbreviation of ${application.title} -->
<fx:application id="epssms" name="${application.title}" version="${application.version}"
mainClass="epssms.MainFrame" preloaderClass="epssmspreloader.EPSSMSPreloader">
<fx:param name="language" value="en"/>
<fx:param name="country" value="US"/>
</fx:application>
<!-- Define what classpath to use, all resources will be recopied to the position sepecified by "includes" under the folder "${dist}" -->
<fx:resources id="appRes">
<fx:fileset id="preloader-files" dir="${dist}" type="jar" requiredFor="preloader"
includes="lib/EnterprisePurchaseSellStockManagementSystemPreloader.jar"/>
<fx:fileset id="derbyclient" dir="${dist}" type="jar" includes="lib/derbyclient.jar"/>
<fx:fileset id="derbynet" dir="${dist}" type="jar" includes="lib/derbynet.jar"/>
<fx:fileset id="derby" dir="${dist}" type="jar" includes="lib/derby.jar"/>
<fx:fileset dir="${dist}" type="jar" includes="${application.title}.jar"/>
</fx:resources>
<echo message="Progress: 20%" level="info"/>
</target>
<target name="jar" depends="init">
<echo message="I am target 'jar'" level="info"/>
<fx:jar destfile="${dist}/${application.title}.jar">
<fx:application refid="epssms"/>
<fx:resources>
<fx:fileset refid="preloader-files"/>
<fx:fileset refid="derbyclient"/>
<fx:fileset refid="derbynet"/>
<fx:fileset refid="derby"/>
</fx:resources>
<!-- What to include into result jar file? -->
<fx:fileset dir="${compile}" includes="**/*" excludes="**/*.css"/>
<!-- Customize jar manifest (optional) -->
<manifest>
<attribute name="Implementation-Vendor" value="${application.vendor}"/>
<attribute name="Implementation-Title" value="${application.title}"/>
<attribute name="Implementation-Version" value="${application.version}"/>
<attribute name="SplashScreen-Image" value="splash.jpg"/>
<attribute name="Permissions" value="all-permissions"/>
<attribute name="Codebase" value="*"/>
</manifest>
</fx:jar>
<echo message="Progress: 25%" level="info"/>
</target>
<target name="keystore.check">
<echo message="I am target 'keystore.check'" level="info"/>
<condition property="keystore.exist">
<and>
<available file="${application.vendor}-Keystore"/>
</and>
</condition>
<echo message="Progress: 30%" level="info"/>
</target>
<!-- For generating keys, see http://docs.oracle.com/javase/tutorial/security/toolsign/step3.html -->
<target name="genkey" depends="jar, keystore.check" unless="keystore.exist">
<echo message="I am target 'genkey'" level="info"/>
<genkey verbose="false" validity="90" alias="javafx" storepass="212188" keypass="881212"
keystore="${application.vendor}-Keystore">
<dname>
<param name="CN" value="${application.vendor}"/>
<param name="OU" value="${application.vendor}"/>
<param name="O" value="${application.vendor}"/>
<param name="L" value="wuhan"/>
<param name="ST" value="hubei"/>
<param name="C" value="CN"/>
</dname>
</genkey>
<echo message="Progress: 35%" level="info"/>
</target>
<target name="signjar" depends="genkey">
<echo message="I am target 'signjar'" level="info"/>
<fx:signjar verbose="false" destdir="${dist}" alias="javafx" keypass="881212"
keystore="${application.vendor}-Keystore" storepass="212188">
<fx:fileset dir="${dist}" includes="${application.title}.jar"/>
<fx:fileset dir="${dist}" includes="lib/*.jar"/>
</fx:signjar>
<echo message="Progress: 70%" level="info"/>
</target>
<target name="deploy" depends="signjar" description="Deploying JavaFX Applications (RIA-Web)">
<echo message="I am target 'deploy'" level="info"/>
<fx:deploy verbose="false" offlineAllowed="false" width="600" height="400" embeddedWidth="100%"
embeddedHeight="100%" embedJNLP="true" outdir="${dist}" outfile="${application.title}">
<fx:application refid="epssms"/>
<fx:resources refid="appRes"/>
<fx:info category="${application.title}" license="GPL" copyright="by ${application.vendor}"
description="It is ${application.title}." title="${application.title}"
vendor="${application.vendor}"/>
<fx:template file="${web}/index_template.html" tofile="${dist}/${application.title}.html"/>
<fx:callbacks>
<fx:callback name="onGetSplash">getSplash</fx:callback>
</fx:callbacks>
<!-- Request elevated permissions which requires signing all JAR files related to application (including the application jar itself). It requires also that the application does not run in the sandbox -->
<fx:permissions elevated="true" cacheCertificates="true"/>
</fx:deploy>
<echo message="Progress: 90%" level="info"/>
</target>
<target name="main" depends="deploy">
<echo message="I am target 'main'" level="info"/>
<java jar="${dist}/${application.title}.jar" fork="true"/>
<echo message="Progress: 100%" level="info"/>
</target>
</project>
这个是用来打包企业进销存管理系统的。
public static void main(String arg[]) {
fianal.launch(arg);
}
报的错误:
Exception in Application constructor
Exception in thread "main" java.lang.RuntimeException: Unable to construct Application instance: class fianal
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.access$000(Unknown Source)
at com.sun.javafx.application.LauncherImpl$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
... 4 more
Caused by: java.lang.ExceptionInInitializerError
at fianal.<init>(fianal.java:63)
... 8 more
Caused by: java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found
at javafx.scene.image.Image.validateUrl(Unknown Source)
at javafx.scene.image.Image.<init>(Unknown Source)
at Ball.<clinit>(Ball.java:16)
... 9 more
Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found
... 12 more
[/quote]
可以正常运行了,但是打包出错了,
init-fx-tasks:
[taskdef] Could not load definitions from resource com/sun/javafx/tools/ant/antlib.xml. It could not be found.
do-deploy:
BUILD FAILED
C:\Users\Administrator\Desktop\build.xml:87: Problem: failed to create task or type javafx:com.sun.javafx.tools.ant:resources
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
求大神指示
public static void main(String arg[]) {
fianal.launch(arg);
}
报的错误:
Exception in Application constructor
Exception in thread "main" java.lang.RuntimeException: Unable to construct Application instance: class fianal
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.access$000(Unknown Source)
at com.sun.javafx.application.LauncherImpl$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
... 4 more
Caused by: java.lang.ExceptionInInitializerError
at fianal.<init>(fianal.java:63)
... 8 more
Caused by: java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found
at javafx.scene.image.Image.validateUrl(Unknown Source)
at javafx.scene.image.Image.<init>(Unknown Source)
at Ball.<clinit>(Ball.java:16)
... 9 more
Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found
... 12 more