Im having trouble on calling my Loop that i created to be placed on the JTextField. Im only a beginner on GUI so i don't understand what i am missing or lacking . Please Help me.
the program must print a box of period if the user enters 1 and box of asterisk if the user
enters 2. and if the user enters 2 or more an error message will show up.
코드를 다시 편집했습니다. 이것은 내가 무엇을 생각해 냈는지, 문제는 내가 Jtextarea가 인쇄물을 쌓아 두는 숫자를 다시 입력 한 후, 그것이 새로 고쳐지지 않는다는 것입니다. 왜 그런지 모르겠군요. 예를 들어 1을 입력하면 마침표 상자에 쇼핑하게됩니다. 내가 별표의 상자가 기간의 상자 아래에 표시 .and 그냥 지금Jtextfield에서 루프를 호출하는 방법
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Box extends JFrame{
private JLabel numL,resultL;
private JTextField numTF;
private JTextArea resultTF;
private JButton printB,exitB;
private PrintButtonHandler pbHandler;
private ExitButtonHandler exitHandler;
public Box(){
numL=new JLabel("Enter 1 or 2", SwingConstants.CENTER);
resultL=new JLabel("Result",SwingConstants.CENTER);
numTF=new JTextField(20);
//resultTF=new JTextField(20);
resultTF = new JTextArea(5,5);
printB=new JButton("Print");
pbHandler=new PrintButtonHandler();
printB.addActionListener(pbHandler);
exitB=new JButton("Exit");
exitHandler= new ExitButtonHandler();
exitB.addActionListener(exitHandler);
setTitle("BOX");
Container p=getContentPane();
p.setLayout(new GridLayout(5,1));
p.add(numL);
p.add(numTF);
p.add(resultL);
p.add(resultTF);
p.add(printB);
p.add(exitB);
setSize(600,600);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private class PrintButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
//Box1 p=new Box1();
int num,height=5,width=5,numLL;
numLL=Integer.parseInt(numTF.getText());
Font f = resultTF.getFont();
resultTF.setFont(new Font(Font.MONOSPACED, f.getStyle(), f.getSize()));
if(numLL==1){
for(int i = 0; i < 5; i++) {
for(int j = 0; j < 5; j++) {
resultTF.append(".");
}
resultTF.append("\n");
}
}else if(numLL==2){
for(int i = 0; i < 5; i++) {
for(int j = 0; j < 5; j++) {
resultTF.append("*");
}
resultTF.append("\n");
}
}else if(numLL>2){
resultTF.append("NOT 1 OR 2:");
}
}
}
private class ExitButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
System.exit(0);
}
}
public static void main(String[]args){
Box p=new Box();
}
}
문제가 정확히 무엇입니까? – Radiodef
PrintButtonHandler 부분입니다. 루프를 실행하는 프로그램을 가져올 수 없습니다. –
그것은 나를 위해 잘 작동합니다. 'System.out.print'가'resultTF' 같은 것으로 출력 될 것으로 기대하고 있습니까? – Radiodef