나는 스윙이 새로운데 아무도 나를 도와 줄 수 없다.왜 내 라벨이 보이지 않습니까?
내 "라벨"을 표시하지 않고 대신 "패널"클래스에있는 구성 요소 만 표시합니다.
한 가지 더 궁금한 점이 있으면 누구나 LayoutManagers에 대해 설명해 주실 수 있습니까? 2 개 이상의 LayoutManager를 프레임에서 사용할 수 있습니까? 프레임에 대해 나는 FlowLayout을 사용할 것이고 나는 BoxLayout을 사용할 프레임에 JPanel을 추가했다.
import javax.swing.*;
import java.awt.event.*;
import java.awt.Graphics;
public class JForm1 extends JFrame
{
public JForm1()
{
init();
}
public static void main(String[] args)
{
JForm1 form = new JForm1();
}
public void init()
{
JFrame frame = new JFrame("My Form 1");
frame.setSize(500,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS));
JLabel label = new JLabel("Enter your Name : ");
panel MyPanel = new panel();
frame.getContentPane().add(label);
frame.getContentPane().add(MyPanel);
frame.setVisible(true);
}
}
class panel extends JPanel implements ActionListener
{
JButton submitButton;
JTextField text;
panel()
{
this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
}
public void paintComponent(Graphics g)
{
text = new JTextField("Enter Name here");
text.setSize(100,25);
submitButton = new JButton("Submit");
submitButton.setSize(50,90);
submitButton.setBounds(200, 0, 80, 80);
submitButton.addActionListener(this);
this.add(text);
this.add(submitButton);
}
public void actionPerformed(ActionEvent event)
{
if(event.getSource()==submitButton)
{
System.out.println("The Entered Name is : "+text.getText());
}
}
}
감사합니다. 그것은 도왔다! – Ravitheja
ANSI C와 같은 Java 표준이 있습니까? 어떤 것이 있으면 말해 주시거나 내가 어디에서 찾을 수 있는지 말해 주시겠습니까? – Ravitheja
@Ravitheja 다음은 규약 목록입니다. http://www.oracle.com/technetwork/java/javase/documentation/codeconvtoc-136057.html 특히 명명 규칙 (예 : http : // www. oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html#367 –