Reputation: 81
I have been required by my teacher to draw an object in Java using the graphics class. It could be anything, but that is boring, so I would like to draw something more complex. It is the daedric sword from skyrim, and the picture I am going off of is located here. Anyway (as we are in the third week of computer science 1), I would like to know to draw arcs and then fill them in with a color, such as the blood red marks on the sword. Her is what I have so far:
import java.awt.*;
import javax.swing.*;
class MainPanel extends JPanel {
public void paintComponent(Graphics g) {
Color bloodRed = new Color(187, 10, 30);
g.setColor(bloodRed);
g.fillRect(0, 0, 200, 200);
}
}
public class Lab08 extends JFrame {
public static void main(String[] args) {
JFrame frame = new JFrame("Graphics");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new MainPanel(), BorderLayout.CENTER);
frame.setVisible(true);
}
}
And please don't say "ask your teacher for help, thats why he's there", because the answer is, I can't. He literally has a sign in his room that says "Google It".
Upvotes: 1
Views: 489
Reputation: 21
You can also use the Scanner class to use your custom inputs to be sorted out
Scanner scan=new Scanner(System.in);
for(int i=0;i<5;i++)
{
System.out.println("Enter a character");
String someValue[i]=scan.nextLine();
}
Iterate the process using loops and store it in an array until you have given all the inputs and randomize it
List<String> characters= Arrays.asList(someValue);
Collections.shuffle(characters);
System.out.println(characters);
Upvotes: 0
Reputation: 4849
Assuming you've already got the entered words, you can do something like this:
public static void main(String[] args)
{
String[] enteredWords = {"here", "there", "everywhere"};
List<String> randomWords = Arrays.asList(enteredWords);
Collections.shuffle(randomWords);
System.out.println(randomWords);
}
Upvotes: 2
Reputation: 49
Put the strings in an array and then randomly access the index of the array.
Upvotes: 0