我正在尝试绘制线条JPanel,我已经打了一些墙.我可以让双方失望但是一旦从x线中减去它就会出错.

package GUIstuff;
import java.awt.Graphics;
import javax.swing.JPanel;
public class DrawPanel extends JPanel{
public void paintComponent (Graphics g){
super.paintComponent(g);
int width = getWidth();
int height = getHeight();
int drawCounter = 0; // counters for all the while statements
int drawCounter2 = 0;
int drawCounter3 = 0;
int drawCounter4 = 0;
int x1 = 0; // cords change with the while statemetns
int x2 = 0;
int y1 = 0;
int y2 = 0;
while (drawCounter <= 15){ // counter …Run Code Online (Sandbox Code Playgroud) 我很新Java,我想了解一些概念.我一直在读几本书,但我一直在同一个地方难倒.看下面的代码:
package Grade;
import static java.lang.System.out;
import java.util.*;
public class GradeBook {
private String courseName;
public void setCourseName (String name) {
courseName = name;
}
public String getCourseName() {
return courseName;
}
public void Display() // needs a string to run
{
out.println("Welcome to:" + getCourseName() );
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定为什么setCourseName()需要(字符串名称)在那里或它从哪里获得该值.如果有人试图以外行的方式解释这一点,我们将不胜感激.
出于某种原因,我的陈述不断进入下一行,而没有按照预期进行.
package Employee;
import java.util.Scanner;
import static java.lang.System.out;
public class EmployeeTest {
public static void main (String args[]) {
out.println ("Welcome to employee storer: ");
Scanner imput = new Scanner (System.in);
Employee employee1 = new Employee();// Creates an employee
Employee employee2 = new Employee();
out.println ("Please enter first name: ");
String fName = imput.nextLine(); //reads keyboard
employee1.setfName(fName);// sets first name
out.println("please enter last name: ");
String lName = imput.nextLine();//reads keyboard
employee1.setlName(lName);// sets second name
out.println("Please enter pay: ");
double pay …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用ListIterator从ArrayList打印,我很确定我做错了因为它不起作用但我不知道如何解决它.所有抓住零件编号的线路都不起作用,不确定原因; P.总是赞赏任何帮助:).
package invoice;
import static java.lang.System.out;
import java.util.*;
public class InvoiceTest {
public static void print(){
}
public static void main (String args[]) {
Scanner imput = new Scanner (System.in);
ArrayList lInvoice = new ArrayList() ;
int counter = 0;
int partCounter;
out.println("Welcome to invoice storer 1.0!");
out.println("To start please enter the number of items: ");
partCounter = imput.nextInt();
while (counter < partCounter){
counter++;
out.println("Please enter the part number:");
Invoice invoice1 = new Invoice(); //Makes invoice 1 use the …Run Code Online (Sandbox Code Playgroud)