-1
양식 작성 중. 두 개의 서로 다른 파일에서 프레임을 다음과 같이 만들었습니다. 다음 클래스의 프레임에 패널을 추가하고 싶습니다. 하지만 예외 다음 가지고 : AWT-EventQueue의-0 "스레드에서 예외" JFrame에 동적으로 패널 추가
가 도와주세요 "상위를 : 해결되지 않은 컴파일 문제 addForm1 변수에 해결 될 수 없습니다." 미리 감사드립니다.File: frontPage.java
import java.awt.Color;
import java.util.Calendar;
import javax.swing.*;
import java.awt.event.*;
public class frontPage extends JFrame implements ActionListener
{
//----------*******Variable Declarations*******-------------------
JPanel panelheaderImage, panelSideBar, panelTittle, panelTittleBar;
JLabel labelheaderImage, labelDate, labelTime, labelTittle,
labelBottomImage;
JButton buttonAddRecord, buttonSearch;
JTextField nameSearch;
Calendar currentDate;
String year, month, day;
Object addform1=null;
//--------******FRAME CONSTRUCTOR*********------------------------
frontPage()
{
//------------frame initialization--------
setBackground(Color.BLUE);
setSize(750, 850);
setVisible(true);
setLayout(null);
//------------frame initialization ENDS-----------------------------
//------------Panel Initialization Starts---------------------------
framBottomImage frameimg = new framBottomImage();
frameBottom framebottom = new frameBottom();
frameAddForm addform = new frameAddForm();
addform1= addform;
add(frameimg.panelBottomImage);
add(framebottom.panelBottomText);
panelheaderImage = new JPanel();
panelheaderImage.setBounds(0, 0, 600, 80);
add(panelheaderImage);
panelSideBar = new JPanel();
panelSideBar.setBounds(520, 90, 200, 40);
panelSideBar.setLayout(null);
add(panelSideBar);
panelTittle = new JPanel();
panelTittle.setLayout(null);
panelTittle.setBounds(0, 85, 550, 30);
add (panelTittle);
panelTittleBar = new JPanel();
panelTittleBar.setBounds(0, 150, 450, 40);
panelTittleBar.setLayout(null);
add(panelTittleBar);
//------------Panel Initialization Ends----------------------------
labelheaderImage = new JLabel(new ImageIcon
("C:\\Users\\SUN\\Desktop\\img.jpg"));
panelheaderImage.add(labelheaderImage);
currentDate = Calendar.getInstance();
year = "" + currentDate.get(Calendar.YEAR);
month = "" + currentDate.get(Calendar.MONTH);
day = "" + currentDate.get(Calendar.DAY_OF_MONTH);
labelDate = new JLabel("Date:" + day + "/" + month + "/" + year);
labelDate.setBounds(0, 0, 90, 20);
panelSideBar.add(labelDate);
labelTime = new JLabel("Time:");
labelTime.setBounds(0, 20, 50, 20);
panelSideBar.add(labelTime);
labelTittle = new JLabel("Patient's Case Paper");
labelTittle.setBounds(150, 0, 250, 25);
panelTittle.add(labelTittle);
buttonAddRecord = new JButton("ADD RECORD");
buttonAddRecord.setBounds(25, 0, 110, 25);
buttonAddRecord.addActionListener(this);
panelTittleBar.add(buttonAddRecord);
nameSearch = new JTextField("");
nameSearch.setBounds(170, 0, 110, 25);
panelTittleBar.add(nameSearch);
buttonSearch = new JButton("Search");
buttonSearch.setBounds(320, 0, 100, 25);
panelTittleBar.add(buttonSearch);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource() == buttonAddRecord)
{
add(addForm1);
}
}
}
Another File:
frameAddForm.java
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.*;
public class frameAddForm
{
JPanel panelAddForm;
JLabel labelName, labelFirstName, labelLastName, labelMiddleName;
JTextField textFieldFirstName, textFieldMiddleName, textFieldLastName;
frameAddForm()
{
panelAddForm = new JPanel();
panelAddForm.setLayout(null);
panelAddForm.setBounds(0, 220, 500, 600);
labelName = new JLabel("Name");
labelName.setBounds(20, 30, 50, 20);
panelAddForm.add(labelName);
//----------------------FNAME---------------------------------
labelFirstName = new JLabel("First Name");
labelFirstName.setBounds(100, 50, 80, 10);
panelAddForm.add(labelFirstName);
textFieldFirstName = new JTextField();
textFieldFirstName.setBounds(100, 30, 80, 20);
textFieldFirstName.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
String input = textFieldFirstName.getText();
Pattern p = Pattern.compile("[ 0-9,&%$#@!()*^,\t\n\f\r]");
Matcher m = p.matcher(input);
if (m.find()) {
JOptionPane.showMessageDialog(null, "Please Enter Valid Name",
"Sorry", JOptionPane.ERROR_MESSAGE);
}
}
});
panelAddForm.add(textFieldFirstName);
//-------------------MNAME---------------------------------------------------
labelMiddleName= new JLabel("Middle Name");
labelMiddleName.setBounds(190, 50, 80, 10);
panelAddForm.add(labelMiddleName);
textFieldMiddleName = new JTextField();
textFieldMiddleName.setBounds(190, 30, 80, 20);
textFieldMiddleName.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
String input = textFieldMiddleName.getText();
Pattern p = Pattern.compile("[ 0-9,&%$#@!()*^]");
Matcher m = p.matcher(input);
if (m.find()) {
JOptionPane.showMessageDialog(null, "Please Enter Valid Name",
"Sorry", JOptionPane.ERROR_MESSAGE);
}
}
});
panelAddForm.add(textFieldMiddleName);
//--------------------------labelName--------------------------------------
labelLastName = new JLabel("Last Name");
labelLastName.setBounds(280, 50, 80, 10);
panelAddForm.add(labelLastName);
textFieldLastName = new JTextField();
textFieldLastName.setBounds(280, 30, 80, 20);
textFieldLastName.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
String input = textFieldLastName.getText();
Pattern p = Pattern.compile("[ 0-9,&%$#@!()*^]");
Matcher m = p.matcher(input);
if (m.find()) {
JOptionPane.showMessageDialog(null, "Please Enter Valid Name",
"Sorry", JOptionPane.ERROR_MESSAGE);
}
}
});
panelAddForm.add(textFieldLastName);
}
}