在java中打开单独的窗口,一个是图形小程序,另一个是交互式文本字段
所以我对Java脚本比较陌生,有时间搞得有点乱,似乎在某个方面有些困难。我的编程课上有一个项目,我被分配了一些细节,因为我的老师不想要太多,我希望在我的程序中有一些互动部分。我尝试过扫描仪的使用,总是得到一个只有文本框的白色屏幕,而不是我老师想要显示的图像,没有所说的扫描仪行,我可以有文本框和图形,但无法进行交互
到目前为止,我只得到了显示的图像,作为一个风景简单的人,和一个被注释掉的文本框;我的问题是如何让文本框接受用户输入并分配变量来更改图像和数学
谢谢你的帮助
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.util.Scanner;
import java.net.*;
import java.io.Console;
public class Project extends Applet// implements ActionListener
{
/*TextField inputLine = new TextField(50);
public Project() {
add(inputLine);
inputLine.addActionListener(this);
}
public void actionPerformed(ActionEvent event) {
//Scanner user_input = new Scanner(System.in);
String s = inputLine.getText();
String sUp = s.toUpperCase();
inputLine.setText(sUp);
*/ // double X = user_input.nextInt();
public void paint(Graphics g)
{
//Foreground
setForeground(Color.green);
Expo.fillRectangle(g,0,0,1000,1000);
Expo.setColor(g,Expo.lightBlue);
Expo.fillRectangle(g,0,0,1000,200);
Expo.setColor(g,Expo.black);
//Variables
double X = 10;
double Y = 15;
double Z = X + Y;
//Drawn Words
Expo.drawString(g,"Brenden Noonen",10,20); //Heading
//Hair
Expo.setColor(g,Expo.gold);
Expo.fillArc(g,500,50,55,30,0,360);
Expo.setColor(g,Expo.black);
//Math
Expo.drawString(g,"Math: X + Y = Z",10,40);
Expo.drawString(g,"X: 10, Y: 15",10,60);
Expo.drawString(g,X + Y + "=" + Z,10,80);
Expo.drawString(g,"Answer: " + Z,10,100);
//Filled Rectangles Neck
Expo.setColor(g,Expo.lightTan);
Expo.fillRectangle(g,475,75,525,200);
Expo.setColor(g,Expo.black);
//Expo.drawRoundedRect(g,325,500,675,1000);
//Drawn Rectangles Neck
Expo.drawRectangle(g,475,75,525,200);
//Drawn Circles
//Expo.drawCircle(g,500,325,150);
//Filled Circles
Expo.setColor(g,Expo.lightTan);
Expo.fillCircle(g,500,75,50); //Face Fill
Expo.setColor(g,Expo.black);
Expo.fillCircle(g,475,65,5); //Eyes
Expo.fillCircle(g,525,65,5);
//Expo.fillCircle(g,440,265,10);
Expo.drawCircle(g,500,75,50); //Face Outline
//Drawn Rectangles
Expo.drawRectangle(g,25,550,50,575);
//Filled Rectangles
Expo.fillRectangle(g,75,550,100,575);
//Drawn Circles
Expo.drawCircle(g,125,562,12);
//Filled Circles
Expo.fillCircle(g,165,562,12);
//Drawn Arcs
Expo.drawArc(g,500,95,15,10,90,270); //Mouth
Expo.drawArc(g,475,55,10,5,280,80); //Eyebrows
Expo.drawArc(g,525,55,10,5,280,80);
Expo.drawArc(g,500,80,5,12,60,130);//Nose
//Filled Arcs
//Expo.setColor(g,Expo.lightGray);
//Expo.fillArc(g,440,255,15,15,120,240);
//Drawn Ovals
//Filled Ovals
Expo.setColor(g,Expo.lightGray);
Expo.fillOval(g,475,68,4,2); //Eyes color
Expo.fillOval(g,525,68,4,2);
//Shirt
Expo.setColor(g,Expo.red);
Expo.fillOval(g,500,175,75,30); //shoulders
Expo.setColor(g,Expo.black);
Expo.drawOval(g,500,175,75,30); //top outline
Expo.setColor(g,Expo.red);
Expo.fillRectangle(g,440,175,560,300); //shirt
Expo.fillRectangle(g,440,175,425,220); //arm sides
Expo.fillRectangle(g,560,175,575,220);
//Arms
Expo.setColor(g,Expo.tan);
Expo.fillRectangle(g,428,220,438,380);
Expo.fillRectangle(g,563,220,573,380);
Expo.setColor(g,Expo.black);
//Hair Top
Expo.setColor(g,Expo.gold);
Expo.fillArc(g,500,30,55,15,0,360);
//Jeans
Expo.setColor(g,Expo.darkBlue);
Expo.fillRectangle(g,440,301,560,560);
Expo.setColor(g,Expo.black);
Expo.fillRectangle(g,440,540,560,560);
Expo.setColor(g,Expo.green);
Expo.fillRectangle(g,480,360,520,1000);
Expo.setColor(g,Expo.bronze);
//House
Expo.fillRectangle(g,875,150,975,250); //House base
Expo.setColor(g,Expo.black);
Expo.drawRectangle(g,875,150,975,250);
Expo.setColor(g,Expo.bronze);
Expo.fillPolygon(g,875,150,925,75,975,150); //Roof
Expo.setColor(g,Expo.black);
Expo.drawPolygon(g,875,150,925,75,975,150);
Expo.setColor(g,Expo.yellow);
Expo.fillRectangle(g,925,175,950,200);
Expo.setColor(g,Expo.black);
Expo.drawRectangle(g,925,175,950,200);
//Trees
Expo.setColor(g,Expo.brown);
Expo.fillRectangle(g,225,275,275,125);
Expo.setColor(g,Expo.darkGreen);
Expo.fillCircle(g,250,75,65);
}
}
共 (0) 个答案