실례합니다, 전 이것을 처음 사용했습니다. 현재 BlueJ를 사용 중이며 Eclipse의 YouTube 튜토리얼을 사용하고 있지만 BlueJ를 과제로 사용해야합니다.수퍼 클래스를 가질 때 클래스의 생성자를 특정 유형에 적용 할 수 없습니다.
GadgetShop이라는 GUI를 작성하기 만하면됩니다. 정보를 추가하는 버튼이 있습니다. 내 모바일 및 MP3 클래스에서. 또한 수퍼 클래스 인 Gadget이라는 클래스가 있습니다.
그래서 내가 겪고있는 문제는 ArrayLists와 함께 내가 만든 텍스트 상자에 표시하기 위해 클래스에서 정보를 수집하는 것입니다. 내가 배열 목록을 만들었지 만 무엇이 잘못되었는지는 모르겠다. 왜냐하면 주어진 클래스에 가제트의 생성자 가젯을 적용 할 수 없다.
/**
* Gadget that is a super class for the Mobile Phone and MP3.
* Needs input for the price, weight, model and size.
*/
public class Gadget
{
// Variables
public double price;
public int weight;
public String model;
public String size;
/**
* Constructor for objects of class Gadget
*/
public Gadget(double ThePrice, int TheWeight, String TheModel, String TheSize)
{
// initialise instance variables
price = ThePrice;
weight = TheWeight;
model = TheModel;
size = TheSize;
}
public double price()
{
return price;
}
public int weight()
{
return weight;
}
public String model()
{
return model;
}
public String size()
{
return size;
}
public void print()
{
System.out.println("The price of the gadget is " + price + " pounds");
System.out.println("The weight is " + weight + " grams");
System.out.println("The model is " + weight);
System.out.println("The size is " + size);
}
}
가 실제로 나는이 문제를 해결할 수 있도록 무엇을 의미 하는가, 무엇을 수집하기 위해 권장되는 방법 :
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.ArrayList;
public class GadgetShop implements ActionListener
{
private JTextField model, price, weight, size, credit, memory, phoneNo, duration, download, displayNumber;
private JButton addMobile, addMP3, clear, displayAll;
//These JTextField's are for the labels
private JTextField model2, price2, weight2, size2, credit2, memory2, phoneNo2, duration2, download2, displayNumber2;
private JFrame frame;
private ArrayList<Gadget> gadgetDetails;
public GadgetShop()
{
makeFrame();
}
public static void main (String args[]){
ArrayList<Gadget> GadgetList = new ArrayList<Gadget>();
Gadget Object = new Gadget();
GadgetList.add(Object.Gadget(model, price, weight, size));
}
public void addGadget(Gadget newGadget)
{
gadgetDetails = new ArrayList<Gadget>();
gadgetDetails.add(newGadget);
model.setText("s6");
내 가젯이 있습니다 : 여기
은 GadgetShop에 필요한 코드입니다 버튼을 클릭 할 때 내 텍스트 상자에 입력 할 클래스의 정보? (클릭 수에 대한 버튼을 활성화하고 정보를 추가하는 방법을 알고 있지만 검색하는 가장 좋은 방법은 모르겠다.)
읽어 주셔서 감사합니다. 생성자는 네 개의 인수를 필요로하기 때문에 단순히 new Gadget()
를 호출 할 수 없습니다
public Gadget(double ThePrice, int TheWeight, String TheModel, String TheSize)
{
// initialise instance variables
price = ThePrice;
weight = TheWeight;
model = TheModel;
size = TheSize;
}
:
는
에 오신 것을 환영합니다! [둘러보기] (http://stackoverflow.com/tour)를 방문하고 둘러보고 [도움말 센터] (http://stackoverflow.com/help)를 읽으십시오. 특히 [어떻게 묻는가?] 좋은 질문입니까?] (http://stackoverflow.com/help/how-to-ask) 및 [여기에 대해 내가 들려 줄 주제는 무엇입니까?] (http://stackoverflow.com/help/on-topic). * * 완료 * 오류 메시지를 [추가] (http://stackoverflow.com/help/editing)주십시오. –