小编Bla*_*268的帖子

试图用JPanel绘制线条

我正在尝试绘制线条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 swing java-2d jpanel paintcomponent

3
推荐指数
1
解决办法
2万
查看次数

Java中的getter和setter

我很新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()需要(字符串名称)在那里或它从哪里获得该值.如果有人试图以外行的方式解释这一点,我们将不胜感激.

java get set

1
推荐指数
1
解决办法
1889
查看次数

声明落到下一行

出于某种原因,我的陈述不断进入下一行,而没有按照预期进行.

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)

java

0
推荐指数
1
解决办法
112
查看次数

使用ListIterator打印数组列表

我正在尝试使用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)

java iterator

0
推荐指数
1
解决办法
6678
查看次数

标签 统计

java ×4

get ×1

iterator ×1

java-2d ×1

jpanel ×1

paintcomponent ×1

set ×1

swing ×1