私は、すべてのクラスを管理するメイン クラス ( mdiform ) があるプロジェクトで作業しています。JInternalFrame を使用してPurchaseMasterクラスを 1 つ作成しましたが、それをいくつかのタブで表示したいと考えています。
私はこのようなコードを作りました:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class PurchaseMaster extends JInternalFrame implements ActionListener
{
JTabbedPane tabbedPane;
JPanel panel1;//,panel2;
JOptionPane op;
mdiform m;
PurchaseMaster p;
JLabel lblrtmt,lblsale,lblform,lblto,lblmaterial,lblload,lblpaid,lbldeposit,lblbalance,lbldlname,lblpur,lblinvoice,lbldate,lblparty,lbltrucktype,lbltruckno,lblitem,lblqty,lblrate;
JButton btnreset,btnsave,btncancel,btnprint;
JTextField txtfrom,txtto,txtload,txtdeposit,txtpaid,txtbal,txtdl,txtcalu,txtinvoice,txtslip,txtparty,txttruckno,txtrate;
JComboBox cmaterial,ctrucktype,citem,cqty;
String type[]={"SLC","Self"};
String qty[]={"Trip","Weight"};
String tno[]={"Coal","Steel","Wood","Rakhad","Iron"};
String[] material={"1","2","3"};
public PurchaseMaster(mdiform m)
{
super("Puchase",false,true,false,true);
setBounds(m.getWidth()/2-300,m.getHeight()/2-200,600,400);
//setBounds(400,600);
setLayout(null);
this.m=m;
JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
// Create the tab pages
createPage1();
//createPage2();
// Create a tabbed pane
tabbedPane = new JTabbedPane();
tabbedPane.addTab( "ADD", panel1 );
//tabbedPane.addTab( "View", panel2 );
topPanel.add( tabbedPane, BorderLayout.CENTER );
add( topPanel );
this.pack();
op=new JOptionPane();
setVisible(true);
setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
try{
m.ConnectDB();
m.msgbox("Work");
m.rs=m.st.executeQuery("Select max(invno)+1 from bricks");
if(m.rs.next())
{
txtinvoice.setText(""+m.rs.getInt(1));
}
m.msgbox("First User ......");
txtinvoice.setText("101");
}
catch(Exception e){}
}
public void createPage1()
{
panel1 = new JPanel();
panel1.setLayout( null );
lblpur=new JLabel("Purchase");
lblpur.setFont(new Font("Times new roman",Font.BOLD,24));
lblpur.setForeground(new Color(100,149,23));
lblpur.setBounds(250,20,200,50);
panel1.add(lblpur);
lblinvoice =new JLabel("Invoice No. : ");
lbldate =new JLabel("Date : ");
lblparty =new JLabel("Party Name : ");
lbltruckno =new JLabel("Truck No. : ");
lbltrucktype =new JLabel("Truck type : ");
lblitem =new JLabel("Invoice No. : ");
lblqty =new JLabel("Qty in : ");
lblrate =new JLabel("Rate : ");
txtcalu=new JTextField();
txtinvoice=new JTextField();
txtparty=new JTextField();
txtrate=new JTextField();
txttruckno=new JTextField();
citem=new JComboBox(type);
cqty=new JComboBox(qty);
ctrucktype=new JComboBox(tno);
btncancel=new JButton("Cancel");
btnprint=new JButton("Print");
btnreset=new JButton("Reset");
btnsave=new JButton("Save");
lblinvoice.setBounds(50,100,80,25);
txtinvoice.setBounds(140,100,50,25);
lbldate.setBounds(440,100,80,25);
lblparty.setBounds(50,135,80,25);
txtparty.setBounds(140,135,400,25);
lbltrucktype.setBounds(50,170,80,25);
ctrucktype.setBounds(140,170,100,25);
lbltruckno.setBounds(350,170,80,25);
txttruckno.setBounds(450,170,100,25);
lblitem.setBounds(50,205,80,25);
citem.setBounds(140,205,100,25);
lblqty.setBounds(260,240,80,25);
cqty.setBounds(350,240,80,25);
txtcalu.setBounds(440,240,80,25);
lblrate.setBounds(260,275,80,25);
txtrate.setBounds(350,275,80,25);
btnreset.setBounds(50,310,100,25);
btnsave.setBounds(160,310,100,25);
btnprint.setBounds(270,310,100,25);
btncancel.setBounds(380,310,100,25);
panel1.add(lblinvoice); panel1.add(lbldate);
panel1.add(lblparty);panel1.add(lbltruckno);panel1.add(lbltrucktype);panel1.add(lblitem); panel1.add(lblqty);panel1.add(lblrate); panel1.add(btncancel);panel1.add(btnprint); panel1.add(btnreset); panel1.add(citem); panel1.add(cqty); panel1.add(ctrucktype);panel1.add(btnsave); panel1.add(txtcalu);panel1.add(txtinvoice);panel1.add(txtparty);panel1.add(txtrate); panel1.add(txtslip); panel1.add(txttruckno);
panel1.add(lblpur);
}
public void actionPerformed(ActionEvent ae)
{
}
}
ここで、m はメイン クラス ( mdiform ) のオブジェクトです。
それはコンパイルしますが、サブメニュー購入をクリックすると、トランザクションメニュー以外にエラーが表示されます。
私のスタックトレースは:
H:\Workspace\Mining Inventory\Project\src>java mdiform
java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1090)
at java.awt.Container.add(Container.java:410)
at PurchaseMaster.createPage1(PurchaseMaster.java:127)
at PurchaseMaster.<init>(PurchaseMaster.java:40)
at mdiform.actionPerformed(mdiform.java:134)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:20
18)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
a:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259
)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:8
33)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMen
uItemUI.java:877)
at java.awt.Component.processMouseEvent(Component.java:6504)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6269)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4860)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832
)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo
main.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo
main.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo
main.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
機能していますが、最大化していません。