gpt4 book ai didi

java - 如何让 java applet 重复自身

转载 作者:行者123 更新时间:2023-12-01 20:24:50 25 4
gpt4 key购买 nike

我有一个 Java 图形实验室,只需单击鼠标即可运行带有 7 个不同“幻灯片”的小程序。在第七张幻灯片之后,我需要找出如何从第一张幻灯片再次运行我的整个小程序。我认为这与 While 循环或重绘方法有关,但我不确定<帮助!

这是我的更好的代码

// Nicholas Barrera
// May 15, 2017
//GraphicsLab09st.java
// This is the student, starting file for Graphics Lab 08.
// This file is identical to Java1520.java.
// This slide show is about Mr. Leon Schram.
// Each student needs to alter this presentation,
// add pictures, add pages, add graphics and make it about him/herself.


import java.awt.*;


public class GraphicsLab09st extends java.applet.Applet
{

int numClicks;
Image picture1, picture2, picture3, picture4, picture5, picture6, picture7, picture8, picture9, picture10, picture11, picture12, picture13;

public void init()
{
numClicks = 0;
picture1 = getImage(getDocumentBase(),"RegularShowSunglasses.jpg");
picture2 = getImage(getDocumentBase(),"film-production.jpg");
picture3 = getImage(getDocumentBase(),"los-angeles.jpg");
picture4 = getImage(getDocumentBase(),"SanAntonio.jpg");
picture5 = getImage(getDocumentBase(),"Brandeis.jpg");
picture6 = getImage(getDocumentBase(),"sound-cloud.png");
picture7 = getImage(getDocumentBase(),"studio.jpg");
picture8 = getImage(getDocumentBase(),"StrangerThings.jpg");
picture9 = getImage(getDocumentBase(),"MazeRunnerBooks.jpg");
picture10 = getImage(getDocumentBase(),"rubiks.jpg");
picture11 = getImage(getDocumentBase(),"CaliLongboarding.jpg");
picture12 = getImage(getDocumentBase(),"Productive.jpg");
picture13 = getImage(getDocumentBase(),"Netflix_Logo.jpg");
}


public void paint(Graphics g)
{
switch (numClicks)
{
case 0: page1(g); break;
case 1: page2(g); break;
case 2: page3(g); break;
case 3: page4(g); break;
case 4: page5(g); break;
case 5: page6(g); break;
case 6: page7(g); break;

}
}

public boolean mouseDown(Event e, int x, int y)
{
numClicks++;
repaint();
return true;
}

//SLIDE 1
public void page1(Graphics g)
{
Expo.setColor(g,Expo.cyan);
g.fillRect(0,0,1000,650);
Expo.setColor(g,Expo.black);
g.setFont(new Font("Arial",Font.BOLD,95));
g.drawString("About Me",218,100);
g.setFont(new Font("Arial",Font.BOLD,50));
g.drawString("Nick Barrera",50,275);
Expo.setColor(g,Expo.red);
Expo.fillStar(g,510,350,175,8);
Expo.setColor(g,Expo.yellow);
Expo.drawThickStar(g,510,350,225,8,25);
Expo.setColor(g,Expo.blue);
Expo.drawThickStar(g,510,350,275,8,25);
g.drawImage(picture1,400,250,this);
g.setFont(new Font("Times Roman",Font.PLAIN,20));
g.drawString("My name is",50,200);
g.drawString("Click once to continue.",750,580);
}



//SLIDE 2
public void page2(Graphics g)
{
Expo.setColor(g,Expo.gold);
g.fillRect(0,0,1000,650);
Expo.setColor(g,Expo.black);
g.setFont(new Font("Algerian",Font.BOLD,100));
g.drawString("PAGE 2",200,100);
Expo.setColor(g,Expo.blue);
Expo.fillRectangle(g,100,250,940,500);
Expo.setColor(g,Expo.chartreuse);
// Expo.drawThickOval(g,260,375,100,150,20);
Expo.drawThickRectangle(g,15,205,590,590,20);
g.drawImage(picture3,25,215,this);
g.drawImage(picture4,615,280,this);
Expo.setColor(g,Expo.blue);
g.setFont(new Font("Times Roman",Font.PLAIN,20));
g.drawString("I was born in the Los Angeles, CA and moved to San Antonio, TX in 2005.",100,190);
g.drawString("Click once to continue.",750,580);
}



//SLIDE 3
public void page3(Graphics g)
{
Expo.setColor(g,Expo.magenta);
g.fillRect(0,0,1000,650);
Expo.setColor(g,Expo.black);
g.setFont(new Font("Impact",Font.BOLD,100));
g.drawString("PAGE 3",200,100);
Expo.setColor(g,Expo.darkBlue);
Expo.fillRoundedRectangle(g,460,220,960,580,50);
Expo.drawRandomBurst(g,268,394,185,2500);
g.drawImage(picture5,150,285,this);
g.drawImage(picture2,520,240,this);
g.setFont(new Font("Times Roman",Font.PLAIN,20));
g.drawString("I am a juinior at Brandeis high school and intested in studying film production in college",100,150);
g.drawString("and becoming a Hollywood Producer/Music Artist in Los Angles, California is my dream.",100,175);
g.drawString("Click once to continue.",750,600);
}



//SLIDE 4
public void page4(Graphics g)
{
Expo.setColor(g,Expo.darkGreen);
g.fillRect(0,0,1000,650);
Expo.setColor(g,Expo.black);
g.setFont(new Font("SansSeriff",Font.BOLD,100));
g.drawString("PAGE 4",200,100);
g.drawImage(picture6,40,200,this);
g.drawImage(picture7, 500,200,this);
Expo.setColor(g,Expo.black);
g.setFont(new Font("Times Roman",Font.PLAIN,20));
g.drawString("The studio I recorded at is called The Living Room Studios.",420,530);
g.drawString("My group name is The Infinity Collective or ICE.",50,480);
g.drawString("I also hope to do something in music and I actually have recorded two songs and",75,150);
g.drawString("have them on soundcloud, a database that shares many artist's music.",75,175);
Expo.setColor(g,Expo.blue);
g.drawString("Click once to continue.",750,580);
}



//SLIDE 5
public void page5(Graphics g)
{
Expo.setColor(g,Expo.black);
g.fillRect(0,0,1000,650);
Expo.setColor(g,Expo.red);
g.setFont(new Font("Garamond",Font.BOLD,100));
g.drawString("PAGE 5",200,100);
g.drawImage(picture8,40,200,this);
g.drawImage(picture9, 500,200,this);
Expo.setColor(g,Expo.red);
g.setFont(new Font("Times Roman",Font.PLAIN,20));
g.drawString("The Maze Runner series by James Dashner is by far my favorite.",320,530);
g.drawString("My hobbies are reading books, playing basketball, and watching movies.",75,150);
Expo.setColor(g,Expo.blue);
g.drawString("Click once to continue.",750,580);
}



//SLIDE 6
public void page6(Graphics g)
{
Expo.setColor(g,Expo.tan);
g.fillRect(0,0,1000,650);
Expo.setColor(g,Expo.black);
g.setFont(new Font("Algerian",Font.BOLD,100));
g.drawString("PAGE 6",200,100);
g.setFont(new Font("Times Roman",Font.PLAIN,20));
g.drawString("My other interest are playing video games, skating and challenging my mind to think with puzzles.",55,150);
g.drawImage(picture10,75,200,this);
g.drawString("I can solve a Rubik's cube in under 2 minutes.",45,500);
g.drawString("I love longboarding more than doing actual skate tricks.",500,520);
g.drawImage(picture11,470,200,this);
Expo.setColor(g,Expo.blue);
g.setFont(new Font("Times Roman",Font.PLAIN,20));
g.drawString("Click once to continue.",750,580);
}



//SLIDE 7
public void page7(Graphics g)
{
Expo.setColor(g,Expo.lightBlue);
g.fillRect(0,0,1000,650);
Expo.setColor(g,Expo.black);
g.setFont(new Font("Bold",Font.BOLD,100));
g.drawString("PAGE 7",200,100);
g.setFont(new Font("Times Roman",Font.PLAIN,20));
g.drawString("Overall I'm a well organized, sporty, and very productive student, who loves fun hobbies and learning new skills",35,150);
g.drawString("",35,165);
g.drawImage(picture12,570,185,this);
g.drawImage(picture13,50,185,this);
Expo.setColor(g,Expo.blue);
g.setFont(new Font("Times Roman",Font.PLAIN,20));
g.drawString("Click once to continue.",750,600);
}
}

最佳答案

如果您只是想返回到第一张幻灯片,那么您所需要的只是在 numClicks 大于 0 的数量时将其重置为 0。幻灯片。

例如:

public boolean mouseDown(Event e, int x, int y)
{
numClicks++;
repaint();
if (numClicks == 6) {
numClicks = 0;
}
return true;
}

这也许不是最好的方法,但它应该可以完成工作。

关于java - 如何让 java applet 重复自身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44028232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com