홈>
학교 프리젠 테이션을 할 때, 나는 자바 부분을 코딩했다. 다른 사람은 내가 모르는 파이썬을했다.
JavaFX를 사용하여 정보를 요청하는 창을 여는 Java 응용 프로그램이 있습니다. 정보를 가져 와서 사용할 파이썬 프로그램에 공급해야합니다.
기본 아이디어는 프로그램이 전화 번호, 제공 업체 및 원하는 메시지를 가져 와서 전송한다는 것입니다.
자바를 통해 파이썬 프로그램을 실행하는 방법이나 그것을 할 때 데이터를 전달하는 방법을 모르겠습니다.
자바 :
package showcase.program;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
//import com.google.common.primitives.Ints;
public class ShowcaseProgram extends Application {
String PhoneNum;
String CarrierNumStr;
String ChoiceStr;
final Button button = new Button ("Submit");
final Label notification = new Label ();
final Label notification2 = new Label ();
@Override
public void start(Stage stage) {
Scene scene = new Scene(new Group(), 500, 500);
final ComboBox CarriersCombo = new ComboBox();
CarriersCombo.getItems().addAll(
"Verison",
"Sprint",
"T-Mobile",
"AT&T",
"MetroPCS",
"Boost Mobile",
"Cricket Wireless",
"Staight Talk",
"Virgin Mobile"
);
final ComboBox ChoiceCombo = new ComboBox();
ChoiceCombo.getItems().addAll(
"Insult",
"Compliment"
);
TextField PhoneNumIn = new TextField ();
PhoneNumIn.setText("Label");
PhoneNumIn.clear();
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
int count = 0;
if (ChoiceCombo.getValue() == null){
notification.setText("You have not selected : insult or compliment");
count++;
}
if (CarriersCombo.getValue() == null){
notification.setText("You have not selected a Carrier!");
count++;
}
if (PhoneNumIn.getText() == null){
notification.setText("You have not entered a Phone number");
count++;
}
if(PhoneNumIn.getText() == null){ //try to get google api imported properly for this to use Ints.tryParse()
notification.setText("Please make sure your phone number is numeric only.");
count++;
}
System.out.println(count);
if (count == 0){
PhoneNum = PhoneNumIn.getText();
CarrierNumStr = CarriersCombo.getValue().toString();
ChoiceStr = ChoiceCombo.getValue().toString();
PhoneNumIn.setText(null);
CarriersCombo.setValue(null);
ChoiceCombo.setValue(null);
notification.setText("Thank you");
} else {
notification2.setText("The information you inputed is incorrect, please try again.");
}
}
});
GridPane grid = new GridPane();
grid.setVgap(4);
grid.setHgap(10);
grid.setPadding(new Insets(5, 5, 5, 5));
grid.add(new Label("Phone Number :"), 0, 0);
grid.add(PhoneNumIn, 1, 0);
grid.add(new Label("Carrier :"),0 , 2);
grid.add(CarriersCombo, 1 , 2);
grid.add(new Label("Choice :"), 0, 3);
grid.add(ChoiceCombo, 1 , 3);
grid.add(button, 1, 4);
grid.add(notification, 1, 5);
grid.add(notification2, 1, 6);
Group root = (Group) scene.getRoot();
root.getChildren().add(grid);
stage.setScene(scene);
stage.show();
}
public static void launchPy(String PhoneNum, int Carrier, String Msg){
}
public static int CarrierToInt(String Carr){
int x;
if (Carr == "Verison"){
x = 7;
} else if (Carr == "Sprint"){
x = 5;
} else if(Carr == "T-Mobile") {
x = 6;
} else if(Carr == "AT&T") {
x = 0;
} else if(Carr == "MetroPCS") {
x = 3;
} else if(Carr == "Boost Mobile") {
x = 1;
} else if(Carr == "Cricket Wireless") {
x = 2;
} else if(Carr == "Straight Talk") {
x = 4;
} else if(Carr == "Virgin Mobile") {
x = 8;
}
else {
x = 0;
}
return x;
}
public static String Message(String ChoiceStr){
int RNG;
RNG = (int )(Math.random() * 1 + 3);
String msg = "";
String[] insults = new String[5];
String[] compliments = new String[5];
insults[1] = "Fart You";//preset insults and compliments go here
insults[2] = "";
insults[3] = "you stink!";
compliments[1] = "Nice Hair";
if (ChoiceStr == "Insult"){
msg = insults[RNG];
} else {
msg = compliments[RNG];
}
return msg;
}
public static void main(String[] args) {
while(true) {
launch(args);
}
}
}
파이썬 프로그램은 launchPy 메소드에 제공된대로 3 개의 입력을 받도록 설정되어 있습니다.
이상적으로는 (의사)와 유사합니다
public static void launchPy(String PhoneNum, int Carrier, String Msg){
string pythonLocation = "/home/...";
//run python(pythonLocation, PhoneNum, Carrier, Msg)
}
그러나 나는 그 부분을 수행하는 방법을 모른다.
감사합니다!
- 답변 # 1
- 답변 # 2
시도 :
Process process; String commands = "python ... " ProcessBuilder pb = new ProcessBuilder(); pb.command(commands); process = pb.start();
관련 자료
- python - 프로그램이 출력을 실행하지 않는 이유는 무엇입니까?
- Python을 사용하여 Python을 사용하여 CLI 프로그램을 실행하는 방법
- 우분투에서 파이썬을 실행하는 잘못된 구문 얻기
- tkinter에서 버튼을 사용하여 별도의 파이썬 프로그램을 어떻게 호출합니까?
- javascript - 내 프로그램이 Atom 내부의 atom-html-preview 및 atom-live-server에서 실행되지만 Chrome이나 JSFiddle에서는 실행되지 않는 이유는 무엇입니까?
- numpy - 파이썬에서이 코드를 실행 한 후이 오류가 계속 나타납니다
- java - 프로그램을 실행하지 않고 몇 번이나 실행합니까
- tkinter - python - 실행 파일이 올바르게 실행되지 않음
- beginner - 3 자리 자기애 적 숫자 프로그램 - 파이썬&# 128013;
- 파이썬 조롱 - 잘못된 인수 수 오류
- k 초 동안 파이썬 스크립트 실행
- PHP에서 Python 프로그램을 실행하고 HTML 내에서 반환 값을 사용하는 방법은 무엇입니까?
- Python에서 KeyboardInterrupt를 사용할 때 어떻게 프로그램을 중지 할 수 없습니까?
- java - 프로그램이 실행되는 동안 사용자가 프로그램을 종료 할 때 프로그램을 반복해야합니까?
- 파이썬의 우박 프로그램
- Python 프로그램은 pycharm에서만 작동하며 다른 곳에서는 작동하지 않습니다
- 파이썬 프로그램에서 입력을 어떻게 사용합니까?
- python - 스레드 오류시 처음부터 프로그램을 다시 시작하는 방법
- list - 쿠폰으로 파이썬 복권 프로그램! (숙제 도움)
- nameerror - name 'threading'is not defined will run python program in terminal