Java程序编译成功,但无法运行,请要出了什么问题?要如何修改?

muhe_ilfaj 2016-06-06 10:00:44
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;

import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.DatePicker;

import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;

import javafx.geometry.Pos;
import javafx.geometry.HPos;
import javafx.geometry.Insets;

import java.util.Calendar;
import java.util.Scanner;
import javafx.util.StringConverter;
import java.util.Locale;
import java.util.Date;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class ExperimentMyProjedt extends Application{
private DatePicker datePicker;
private final String pattern = "yyyy-MM-dd";
private String title[][] = new String[100][100];
private String content[][] = new String[100][100];
private DatePicker[] date = new DatePicker[100];
private TextField tftitle = new TextField();
private TextField tfcontent = new TextField();
private Button btaddopration = new Button("添加任务");
private Button btremoveopration = new Button("删除任务");
private Button btshowopration = new Button("显示任务");
@Override
public void start(Stage primaryStage){
//静态页面
BorderPane pane = new BorderPane();
pane.setRight(null);
pane.setTop(new CustomPane("任务管理系统"));
pane.setLeft(getVBox());
pane.setCenter(initUI());


//动态页面
btaddopration.setOnAction(e -> addOpration());
btremoveopration.setOnAction(e -> removeOpration());
btshowopration.setOnAction(e -> showOpration());


//GUI显示
Scene scene = new Scene(pane,450,400);
primaryStage.setScene(scene);
primaryStage.setTitle("任务管理系统");
primaryStage.show();
}

public static void main(String[] args) {
// TODO Auto-generated method stub
Locale.setDefault(Locale.US);
Application.launch(args);

}


private VBox getVBox(){
VBox vBox = new VBox();
vBox.setPadding(new Insets(15,5,5,5));
vBox.getChildren().add(new Label("我的选项"));
Button[] MyOprations ={btaddopration,btremoveopration,btshowopration};
for(Button MyOpration : MyOprations){
VBox.setMargin(MyOpration, new Insets(10,0,0,15));
vBox.getChildren().add(MyOpration);
}

return vBox;
}

protected VBox initUI() {
VBox vbox = new VBox(20);
vbox.setStyle("-fx-padding: 10;");
datePicker = new DatePicker();
StringConverter converter = new StringConverter<LocalDate>() {
DateTimeFormatter dateFormatter =
DateTimeFormatter.ofPattern(pattern);
@Override
public String toString(LocalDate date) {
if (date != null) {
return dateFormatter.format(date);
} else {
return "";
}
}
@Override
public LocalDate fromString(String string) {
if (string != null && !string.isEmpty()) {
return LocalDate.parse(string, dateFormatter);
} else {
return null;
}
}
};
datePicker.setConverter(converter);
datePicker.setPromptText(pattern.toLowerCase());
datePicker.setValue(LocalDate.now());
GridPane gridPane = new GridPane();
gridPane.setHgap(10);
gridPane.setVgap(10);
Label checkInlabel = new Label("任务日期");
gridPane.add(checkInlabel, 0, 0);
GridPane.setHalignment(checkInlabel, HPos.LEFT);
gridPane.add(datePicker, 0, 1);
gridPane.add(new Label("任务标题"),0,2);
gridPane.add(tftitle,0,3);
gridPane.add(new Label("任务内容"),0,4);
gridPane.add(tfcontent, 0, 5);
vbox.getChildren().add(gridPane);
datePicker.requestFocus();
return vbox;
}
//addOPration 方法
private void addOpration(){
int i,j=0;
DatePicker[] testdate = new DatePicker[10];
testdate[0] = datePicker;
for(i=0; i<=date.length; i++){
if(testdate[0] == date[i]){
title[i][(title[i].length) + 1] = tftitle.getText();
content[i][(content[i].length) + 1] = tfcontent.getText();
j=j+1;
tftitle.setText("");
tfcontent.setText("");
break;
}
else{
continue;
}

}
if(j==1){

}
else{
title[i+1][0] = "tftitle";
content[i+1][0] = "tfcontent";
}
}

private void removeOpration(){
int i,j=0;
DatePicker[] testdate = new DatePicker[10];
testdate[0] = datePicker;
for(i=0; i<=date.length; i++){
if(testdate[0] == date[i]){
title[i][(title[i].length)] = "";
content[i][(content[i].length)] = "";
j=j+1;
break;
}
else{
continue;
}
}
}

private void showOpration(){
int i,j=0;
DatePicker[] testdate = new DatePicker[10];
testdate[0] = datePicker;
for(i=0; i<=date.length; i++){
if(testdate[0] == date[i]){
tftitle.setText(title[i][(title[i].length)]);
tfcontent.setText(content[i][(content[i].length)]);
j=j+1;
break;
}
else{
continue;
}
}
}

}


class CustomPane extends StackPane{
public CustomPane(String title){
getChildren().add(new Label(title));
setStyle("-fx-border-color:red");
}
}







...全文
326 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
androidCrazyZero 2016-07-12
  • 打赏
  • 举报
回复
厉害 厉害厉害
define_us 2016-07-12
  • 打赏
  • 举报
回复

package Pack1;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;

import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.DatePicker;

import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;

import javafx.geometry.Pos;
import javafx.geometry.HPos;
import javafx.geometry.Insets;

import java.util.Calendar;
import java.util.Scanner;
import javafx.util.StringConverter;
import java.util.Locale;
import java.util.Date;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;


import javafx.event.ActionEvent;//修改1
import javafx.event.EventHandler;

public class ExperimentMyProjedt extends Application{
private DatePicker datePicker;
private final String pattern = "yyyy-MM-dd";
private String title[][] = new String[100][100];
private String content[][] = new String[100][100];
private DatePicker[] date = new DatePicker[100];
private TextField tftitle = new TextField();
private TextField tfcontent = new TextField();
private Button btaddopration = new Button("添加任务");
private Button btremoveopration = new Button("删除任务");
private Button btshowopration = new Button("显示任务");
@Override
public void start(Stage primaryStage){
//静态页面
BorderPane pane = new BorderPane();
pane.setRight(null);
pane.setTop(new CustomPane("任务管理系统"));
pane.setLeft(getVBox());
pane.setCenter(initUI());
ActionEvent e;

//动态页面
//修改2
btaddopration.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event) {
addOpration();
System.out.println("add");
}
});
btremoveopration.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event) {
removeOpration();
System.out.println("remove");
}
});
btshowopration.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent event) {
showOpration();
System.out.println("show");
}
});


//GUI显示
Scene scene = new Scene(pane,450,400);
primaryStage.setScene(scene);
primaryStage.setTitle("任务管理系统");
primaryStage.show();
}

public static void main(String[] args) {
// TODO Auto-generated method stub
Locale.setDefault(Locale.US);
Application.launch(args);

}


private VBox getVBox(){
VBox vBox = new VBox();
vBox.setPadding(new Insets(15,5,5,5));
vBox.getChildren().add(new Label("我的选项"));
Button[] MyOprations ={btaddopration,btremoveopration,btshowopration};
for(Button MyOpration : MyOprations){
VBox.setMargin(MyOpration, new Insets(10,0,0,15));
vBox.getChildren().add(MyOpration);
}
return vBox;
}

protected VBox initUI() {
VBox vbox = new VBox(20);
vbox.setStyle("-fx-padding: 10;");
datePicker = new DatePicker();
StringConverter converter = new StringConverter<LocalDate>() {
DateTimeFormatter dateFormatter =
DateTimeFormatter.ofPattern(pattern);
@Override
public String toString(LocalDate date) {
if (date != null) {
return dateFormatter.format(date);
} else {
return "";
}
}
@Override
public LocalDate fromString(String string) {
if (string != null && !string.isEmpty()) {
return LocalDate.parse(string, dateFormatter);
} else {
return null;
}
}
};
datePicker.setConverter(converter);
datePicker.setPromptText(pattern.toLowerCase());
datePicker.setValue(LocalDate.now());
GridPane gridPane = new GridPane();
gridPane.setHgap(10);
gridPane.setVgap(10);
Label checkInlabel = new Label("任务日期");
gridPane.add(checkInlabel, 0, 0);
GridPane.setHalignment(checkInlabel, HPos.LEFT);
gridPane.add(datePicker, 0, 1);
gridPane.add(new Label("任务标题"),0,2);
gridPane.add(tftitle,0,3);
gridPane.add(new Label("任务内容"),0,4);
gridPane.add(tfcontent, 0, 5);
vbox.getChildren().add(gridPane);
datePicker.requestFocus();
return vbox;
}
//addOPration 方法
private void addOpration(){
int i,j=0;
DatePicker[] testdate = new DatePicker[10];
testdate[0] = datePicker;
for(i=0; i<=date.length; i++){
if(testdate[0] == date[i]){
title[i][(title[i].length) + 1] = tftitle.getText();
content[i][(content[i].length) + 1] = tfcontent.getText();
j=j+1;
tftitle.setText("");
tfcontent.setText("");
break;
}
else{
continue;
}
}
if(j==1){

}
else{
title[i+1][0] = "tftitle";
content[i+1][0] = "tfcontent";
}
}

private void removeOpration(){
int i,j=0;
DatePicker[] testdate = new DatePicker[10];
testdate[0] = datePicker;
for(i=0; i<=date.length; i++){
if(testdate[0] == date[i]){
title[i][(title[i].length)] = "";
content[i][(content[i].length)] = "";
j=j+1;
break;
}
else{
continue;
}
}
}

private void showOpration(){
int i,j=0;
DatePicker[] testdate = new DatePicker[10];
testdate[0] = datePicker;
for(i=0; i<=date.length; i++){
if(testdate[0] == date[i]){
tftitle.setText(title[i][(title[i].length)]);
tfcontent.setText(content[i][(content[i].length)]);
j=j+1;
break;
}
else{
continue;
}
}
}

}


class CustomPane extends StackPane{
public CustomPane(String title){
getChildren().add(new Label(title));
setStyle("-fx-border-color:red");
}
}





修改了两处,在我这可以运行了。但是程序仍然有其他问题,你自己慢慢修改吧。
ZQWFD1984 2016-07-12
  • 打赏
  • 举报
回复
这题谁能解答出来真是牛掰啊~!

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧