0
나는 탭 응용 프로그램이 있습니다. 탭 중 하나에 회사 이름을 입력 할 수 있으며 다른 탭에 입력 한 이름으로 변경해야합니다. 두 클래스가 있습니다.이 상속을 사용할 수 없습니다.
이 코드에서 변경하겠다고 말합니다 About.setCompanyName (str); 정적
I는보고하고 오류에 여기
package CourseProject;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import javax.swing.*;
public class Options extends JPanel{
private JLabel changeLabel;
private JTextField changeName;
private JButton setName;
private JButton exitButton;
public Options(){
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.NORTH;
setBackground(Color.WHITE);
super.setLayout(gridbag);
c.insets = new Insets(10, 10, 10, 10);
changeLabel = new JLabel("Change Company Name:");
changeName = new JTextField("", 10);
setName = new JButton("Set New Name");
exitButton = new JButton("Exit");
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 2;
add(changeLabel, c);
c.gridx = 0;
c.gridy = 1;
add(changeName, c);
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 1;
add(setName, c);
setName.addActionListener(new setNameAction());
c.gridx = 1;
c.gridy = 2;
add(exitButton, c);
exitButton.addActionListener(new exitApp());
exitButton.setSize(40,40);
}
class setNameAction implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String str;
str = changeName.getText();
About.SetCompanyName(str);
changeName.setText("");
}
}
class exitApp implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
}
그리고 "정보 유형에서 비 정적 메소드 SetCompanyName (문자열)에 대한 정적 참조를 만들 수 없음"이는 내 포함 "정보"입니다 세터. 그것은 방법 및 변수 정적을 만들기 위해 저를 요구하지만 난을 사용하여 (당신은 정적 SetCompanyName를 호출하고
About.SetCompanyName(str);
이 라인에 그것을
package CourseProject;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class About extends JPanel{
private JLabel programInfoLabel;
private JLabel programInfo;
private JLabel programmerLabel;
private JLabel programmer;
private JLabel companyLabel;
JLabel company;
public String companyName = "enter a company name in options";
public About() {
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.NORTH;
setBackground(Color.WHITE);
super.setLayout(gridbag);
c.insets = new Insets(10, 10, 10, 10);
programInfoLabel = new JLabel("Program Information:");
programInfo = new JLabel("This is the CIS355A course project application");
programmerLabel = new JLabel("Programmer:");
programmer = new JLabel("Kevin Rankin");
companyLabel = new JLabel("Company Name:");
company = new JLabel(companyName);
c.gridx = 0;
c.gridy = 0;
add(programInfoLabel, c);
c.gridx = 1;
c.gridy = 0;
add(programInfo, c);
c.gridx = 0;
c.gridy = 1;
add(programmerLabel, c);
c.gridx = 1;
c.gridy = 1;
add(programmer, c);
c.gridx = 0;
c.gridy = 2;
add(companyLabel, c);
c.gridx = 1;
c.gridy = 2;
add(company, c);
}
public void SetCompanyName(String str){
company.setText(str);
}
}
을 당신이 못을 명중 : (이 혼동 것 같다 "최종"과 동일하지 않은) 또는 같은, 먼저 소개 클래스의 인스턴스를 만드는 당신은 방법 정적을해야 하나 내 친구. 나는 마지막과 정적을 혼란스럽게했다 ... 고맙다 more – helloWorldIsAlliKnow
@helloWorldIsAlliKnow 클래스와 메서드를 사용하여 그 클래스의 모든 개체를 초기화하려면 해당 메서드를 정적 또는 해당 클래스를 정적으로 만들 필요가 있는지. – Krishna