我正在使用Netbeans ..我正在尝试创建一个发票申请。所以我在第一个创建和发票jframe表格..这个表格以表格方式接受所有发票详细信息,我已经覆盖了绘制方法来绘制Invoice jframe中的一些行。
现在我已经动态创建了另一个Old Items jframe,当我们单击Button时会从中创建它。此表单接受返回的旧产品的详细信息。我想在OldItems jFrame中绘制一些行。但是当我尝试这样做时,要么在主Invoice表单中绘制线条,要么根本不绘制它们。
有什么方法可以为不同形式调用不同的绘画方法吗? 这是代码:
public class Inovice2 extends javax.swing.JFrame {
JLabel lblSno ;
JLabel lblSn1 ;
JLabel lblSn2 ;[enter image description here][1]
JLabel lblSn3 ;
JLabel lblSn4 ;
JLabel lblSn5 ;
JLabel lblSn6 ;
JLabel lblSn7 ;
JLabel lblSn8 ;
JLabel lblSn9 ;
JLabel lblSn10 ;
JLabel lblItemType ;
JLabel lblDesc ;
JLabel lblPurity;
JLabel lblGrsWgt1;
JLabel lblGrsWgt2;
JLabel lblNetWgt1;
JLabel lblNetWgt2;
JLabel lblRate1 ;
JLabel lblRate2 ;
JLabel lblLbrTyp1 ;
JLabel lblLbrTyp2 ;
JLabel lblLbrChrgs1;
JLabel lblLbrChrgs2;
JLabel lblNoOfPcs1;
JLabel lblNoOfPcs2;
JLabel lblStoneChrgs1 ;
JLabel lblStoneChrgs2 ;
JLabel lblAmt1;
JLabel lblAmt2;
int iTransid;
int iOldFlag =0;
int iPaintFlag =0;
JFrame frmOldItemInvoice = new JFrame();
public Inovice2() {
initComponents();
DateFormat dateFormat = new SimpleDateFormat("dd/MM/YYYY");
Date date = new Date();
txtDate.setText(dateFormat.format(date));
//System.out.println(dateFormat.format(date));
try{
Class.forName("com.mysql.jdbc.Driver");
try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/PJ","root","root")) {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select Cust_name from CUSTOMER_DEtaILS");
while (rs.next())
{
drpdwnCustName.addItem(rs.getString(1));
}}
}catch (ClassNotFoundException | SQLException e){System.out.println(e);}
this.setLayout(null);
setLayout(new FlowLayout());
final Container cn = getContentPane();
cn.setLayout(null);
lblSno = new JLabel();
lblSno.setText("S.No.");
lblSn1 = new JLabel();
lblSn1.setText("1");
lblSn2 = new JLabel();
lblSn2.setText("2");
lblSn3 = new JLabel();
lblSn3.setText("3");
lblSn4 = new JLabel();
lblSn4.setText("4");
lblSn5 = new JLabel();
lblSn5.setText("5");
lblSn6 = new JLabel();
lblSn6.setText("6");
lblSn7 = new JLabel();
lblSn7.setText("7");
lblSn8 = new JLabel();
lblSn8.setText("8");
lblSn9 = new JLabel();
lblSn9.setText("9");
lblSn10 = new JLabel();
lblSn10.setText("10");
lblItemType = new JLabel();
lblItemType.setText("Item Type");
lblDesc = new JLabel();
lblDesc.setText("Description");
lblPurity = new JLabel();
lblPurity.setText("Purity");
lblGrsWgt1 = new JLabel();
lblGrsWgt1.setText("Gross Wgt");
lblGrsWgt2 = new JLabel();
lblGrsWgt2.setText("(In Gms)");
lblNetWgt1 = new JLabel();
lblNetWgt1.setText("Net Wgt");
lblNetWgt2 = new JLabel();
lblNetWgt2.setText("(In Gms)");
lblRate1 = new JLabel();
lblRate1.setText("Rate");
lblRate2 = new JLabel();
lblRate2.setText("(Per gm)");
lblLbrTyp1 = new JLabel();
lblLbrTyp1.setText("Labour Type");
lblLbrChrgs1 = new JLabel();
lblLbrChrgs1.setText("Labour");
lblLbrChrgs2 = new JLabel();
lblLbrChrgs2.setText("Charges");
lblNoOfPcs1= new JLabel();
lblNoOfPcs1.setText("No. Of");
lblNoOfPcs2= new JLabel();
lblNoOfPcs2.setText("Pieces");
lblStoneChrgs1 = new JLabel();
lblStoneChrgs1.setText("Stone &");
lblStoneChrgs2 = new JLabel();
lblStoneChrgs2.setText("Other Charges");
lblAmt1 = new JLabel();
lblAmt1.setText("Amount");
lblAmt2 = new JLabel();
lblAmt2.setText("(In Rs.)");
lblSn1.setBounds(30, 180, 20, 20);
lblSn2.setBounds(30, 205, 20, 20);
lblSn3.setBounds(30, 230, 20, 20);
lblSn4.setBounds(30, 255, 20, 20);
lblSn5.setBounds(30, 280, 20, 20);
lblSn6.setBounds(30, 305, 20, 20);
lblSn7.setBounds(30, 330, 20, 20);
lblSn8.setBounds(30, 355, 20, 20);
lblSn9.setBounds(30, 380, 20, 20);
lblSn10.setBounds(26,405, 20, 20);
lblSno.setBounds(19, 140, 30, 20);
lblItemType.setBounds(68, 140, 100, 20);
lblDesc.setBounds(225, 140, 100, 20);
lblPurity.setBounds(397, 140, 100, 20);
lblGrsWgt1.setBounds(470, 140, 100, 20);
lblGrsWgt2.setBounds(472, 155, 100, 20);
lblNetWgt1.setBounds(559, 140, 100, 20);
lblNetWgt2.setBounds(558, 155, 100, 20);
lblRate1.setBounds(645, 140, 80, 20);
lblRate2.setBounds(635, 155, 80, 20);
lblLbrTyp1.setBounds(720, 140, 100, 20);
lblLbrChrgs1.setBounds(842, 140, 100, 20);
lblLbrChrgs2.setBounds(838, 155, 100, 20);
lblNoOfPcs1.setBounds(935, 140, 100, 20);
lblNoOfPcs2.setBounds(936, 155, 100, 20);
lblStoneChrgs1.setBounds(1060, 140, 150, 20);
lblStoneChrgs2.setBounds(1040, 155, 150, 20);
lblAmt1.setBounds(1190, 140, 850, 20);
lblAmt2.setBounds(1192, 155, 850, 20);
cn.add(lblSn1);
cn.add(lblSn2);
cn.add(lblSn3);
cn.add(lblSn4);
cn.add(lblSn5);
cn.add(lblSn6);
cn.add(lblSn7);
cn.add(lblSn8);
cn.add(lblSn9);
cn.add(lblSn10);
cn.add(lblSno);
cn.add(lblItemType);
cn.add(lblDesc);
cn.add(lblPurity);
cn.add(lblGrsWgt1);
cn.add(lblGrsWgt2);
cn.add(lblNetWgt1);
cn.add(lblNetWgt2);
cn.add(lblRate1);
cn.add(lblRate2);
cn.add(lblLbrTyp1);
cn.add(lblLbrChrgs1);
cn.add(lblLbrChrgs2);
cn.add(lblNoOfPcs1);
cn.add(lblNoOfPcs2);
cn.add(lblStoneChrgs1);
cn.add(lblStoneChrgs2);
cn.add(lblAmt1);
cn.add(lblAmt2);
setSize(1300,1300);
this.repaint();
}
@Override
public void paint(Graphics g) {
super.paint(g);
if (iPaintFlag == 0)
{
// fixes the immediate problem.
Graphics2D g2 = (Graphics2D) g;
Line2D hlin0 = new Line2D.Float(15, 160, 1275, 160);
g2.draw(hlin0);
Line2D hlin1 = new Line2D.Float(15, 200, 1275, 200);
g2.draw(hlin1);
Line2D hlin2 = new Line2D.Float(15, 225, 1275, 225);
g2.draw(hlin2);
Line2D hlin3 = new Line2D.Float(15, 250, 1275, 250);
g2.draw(hlin3);
Line2D hlin4 = new Line2D.Float(15, 275, 1275, 275);
g2.draw(hlin4);
Line2D hlin5 = new Line2D.Float(15, 300, 1275, 300);
g2.draw(hlin5);
Line2D hlin6 = new Line2D.Float(15, 325, 1275, 325);
g2.draw(hlin6);
Line2D hlin7 = new Line2D.Float(15, 350, 1275, 350);
g2.draw(hlin7);
Line2D hlin8 = new Line2D.Float(15, 375, 1275, 375);
g2.draw(hlin8);
Line2D hlin9 = new Line2D.Float(15, 400, 1275, 400);
g2.draw(hlin9);
Line2D hlin10 = new Line2D.Float(15, 425, 1275, 425);
g2.draw(hlin10);
Line2D hlin11 = new Line2D.Float(15, 450, 1275, 450);
g2.draw(hlin11);
Line2D hlin12 = new Line2D.Float(15, 475, 1275, 475);
g2.draw(hlin12);
Line2D hlin13 = new Line2D.Float(1000, 527, 1275, 527);
g2.draw(hlin13);
Line2D hlin14 = new Line2D.Float(1000, 602, 1275, 602);
g2.draw(hlin14);
Line2D hlin15 = new Line2D.Float(1000, 627, 1275, 627);
g2.draw(hlin15);
Line2D hlin16 = new Line2D.Float(1000, 652, 1275, 652);
g2.draw(hlin16);
Line2D vlin0 = new Line2D.Float(15, 160, 15, 475);
g2.draw(vlin0);
Line2D vlin1 = new Line2D.Float(50, 160, 50, 475);
g2.draw(vlin1);
Line2D vlin2 = new Line2D.Float(150, 160, 150, 475);
g2.draw(vlin2);
Line2D vlin3 = new Line2D.Float(370, 160, 370, 475);
g2.draw(vlin3);
Line2D vlin4 = new Line2D.Float(460, 160, 460, 475);
g2.draw(vlin4);
Line2D vlin5 = new Line2D.Float(540, 160, 540, 475);
g2.draw(vlin5);
Line2D vlin6 = new Line2D.Float(620, 160, 620, 475);
g2.draw(vlin6);
Line2D vlin7 = new Line2D.Float(700, 160, 700, 475);
g2.draw(vlin7);
Line2D vlin8 = new Line2D.Float(812, 160, 812, 475);
g2.draw(vlin8);
Line2D vlin9 = new Line2D.Float(912, 160, 912, 475);
g2.draw(vlin9);
Line2D vlin10 = new Line2D.Float(1000, 160, 1000, 652);
g2.draw(vlin10);
Line2D vlin11 = new Line2D.Float(1170, 160, 1170, 652);
g2.draw(vlin11);
Line2D vlin12 = new Line2D.Float(1275, 160, 1275, 652);
g2.draw(vlin12);
}
else
{
Graphics2D g2 = (Graphics2D) g;
Line2D hlin0 = new Line2D.Float(90, 140, 880, 140);
g2.draw(hlin0);
Line2D hlin1 = new Line2D.Float(90, 170, 880, 170);
g2.draw(hlin1);
Line2D hlin2 = new Line2D.Float(90, 195, 880, 195);
g2.draw(hlin2);
Line2D hlin3 = new Line2D.Float(90, 220, 880, 220);
g2.draw(hlin3);
Line2D hlin4 = new Line2D.Float(90, 245, 880, 245);
g2.draw(hlin4);
Line2D hlin5 = new Line2D.Float(90, 270, 880, 270);
g2.draw(hlin5);
Line2D hlin6 = new Line2D.Float(90, 295, 880, 295);
g2.draw(hlin6);
Line2D hlin7 = new Line2D.Float(90, 320, 880, 320);
g2.draw(hlin7);
Line2D hlin8 = new Line2D.Float(90, 345, 880, 345);
g2.draw(hlin8);
Line2D hlin9 = new Line2D.Float(90, 370, 880, 370);
g2.draw(hlin9);
Line2D hlin10 = new Line2D.Float(90, 395, 880, 395);
g2.draw(hlin10);
Line2D hlin11 = new Line2D.Float(90, 420, 880, 420);
g2.draw(hlin11);
Line2D hlin12 = new Line2D.Float(660, 445, 880, 445);
g2.draw(hlin12);
Line2D vlin0 = new Line2D.Float(90, 140, 90, 420);
g2.draw(vlin0);
Line2D vlin1 = new Line2D.Float(140, 140, 140, 420);
g2.draw(vlin1);
Line2D vlin2 = new Line2D.Float(240, 140, 240, 420);
g2.draw(vlin2);
Line2D vlin3 = new Line2D.Float(440, 140, 440, 420);
g2.draw(vlin3);
Line2D vlin4 = new Line2D.Float(540, 140, 540, 420);
g2.draw(vlin4);
Line2D vlin5 = new Line2D.Float(660, 140, 660, 445);
g2.draw(vlin5);
Line2D vlin6 = new Line2D.Float(760, 140, 760, 445);
g2.draw(vlin6);
Line2D vlin7 = new Line2D.Float(880, 140, 880, 445);
g2.draw(vlin7);
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
txtDate = new javax.swing.JTextField();
btnCal = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
btnAddOld = new javax.swing.JButton();
lblCustName = new javax.swing.JLabel();
drpdwnCustName = new javax.swing.JComboBox<>();
lblDate = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
btnCal.setText("<>");
btnCal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCalActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Lucida Grande", 0, 24)); // NOI18N
jLabel1.setText("SALE INVOICE");
btnAddOld.setText("Old Jewellery Purchase");
btnAddOld.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAddOldActionPerformed(evt);
}
});
lblCustName.setText("Customer Name");
drpdwnCustName.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "---Select---" }));
lblDate.setText("Date");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(lblCustName)
.addGap(26, 26, 26)
.addComponent(drpdwnCustName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(50, 50, 50)
.addComponent(lblDate)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtDate, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(27, 27, 27)
.addComponent(btnCal, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(26, 26, 26)
.addComponent(btnAddOld, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(341, 341, 341)
.addComponent(jLabel1)))
.addContainerGap(307, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(17, 17, 17)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblCustName)
.addComponent(drpdwnCustName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblDate)
.addComponent(txtDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnCal)
.addComponent(btnAddOld))
.addContainerGap(428, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void btnCalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtDate.setText(new pj.Calendar().setPickedDate());
}
private void btnAddOldActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//String str[]={"1","2"};
//pj.OldItemInvoice.main(str);
iPaintFlag=1;
frmOldItemInvoice.setSize(600, 700);
JLabel lblOldSno ;
JLabel lblOldSn1 ;
JLabel lblOldSn2 ;
JLabel lblOldSn3 ;
JLabel lblOldSn4 ;
JLabel lblOldSn5 ;
JLabel lblOldSn6 ;
JLabel lblOldSn7 ;
JLabel lblOldSn8 ;
JLabel lblOldSn9 ;
JLabel lblOldSn10 ;
JLabel lblOldItemType ;
JLabel lblOldDesc ;
JLabel lblOldPurity;
JLabel lblOldWgt;
JLabel lblOldRate ;
JLabel lblOldAmt;
JLabel lblOldTtlAmt;
JLabel OldTtlAmt;
JLabel lblNoOfOldItems;
frmOldItemInvoice.setLayout(null);
lblNoOfOldItems = new JLabel();
lblNoOfOldItems.setText("No. Of Old Items");
lblNoOfOldItems.setBounds(350, 50, 125, 25);
frmOldItemInvoice.add(lblNoOfOldItems);
lblOldSno = new JLabel();
lblOldSno.setText("S.No.");
lblOldSn1 = new JLabel();
lblOldSn1.setText("1");
lblOldSn2 = new JLabel();
lblOldSn2.setText("2");
lblOldSn3 = new JLabel();
lblOldSn3.setText("3");
lblOldSn4 = new JLabel();
lblOldSn4.setText("4");
lblOldSn5 = new JLabel();
lblOldSn5.setText("5");
lblOldSn6 = new JLabel();
lblOldSn6.setText("6");
lblOldSn7 = new JLabel();
lblOldSn7.setText("7");
lblOldSn8 = new JLabel();
lblOldSn8.setText("8");
lblOldSn9 = new JLabel();
lblOldSn9.setText("9");
lblOldSn10 = new JLabel();
lblOldSn10.setText("10");
lblOldItemType = new JLabel();
lblOldItemType.setText("Item Type");
lblOldDesc = new JLabel();
lblOldDesc.setText("Description");
lblOldPurity = new JLabel();
lblOldPurity.setText("Purity (%)");
lblOldWgt = new JLabel();
lblOldWgt.setText("Weight (In Gms)");
lblOldRate = new JLabel();
lblOldRate.setText("Rate (Per Gm)");
lblOldAmt = new JLabel();
lblOldAmt.setText("Amount (In Rs. )");
lblOldSn1.setBounds(110, 155, 20, 20);
lblOldSn2.setBounds(110, 180, 20, 20);
lblOldSn3.setBounds(110, 205, 20, 20);
lblOldSn4.setBounds(110, 230, 20, 20);
lblOldSn5.setBounds(110, 255, 20, 20);
lblOldSn6.setBounds(110, 280, 20, 20);
lblOldSn7.setBounds(110, 305, 20, 20);
lblOldSn8.setBounds(110, 330, 20, 20);
lblOldSn9.setBounds(110, 355, 20, 20);
lblOldSn10.setBounds(106, 380, 20, 20);
lblOldSno.setBounds(100, 125, 30, 20);
lblOldItemType.setBounds(150, 125, 100, 20);
lblOldDesc.setBounds(250, 125, 100, 20);
lblOldPurity.setBounds(450, 125, 100, 20);
lblOldWgt.setBounds(550, 125, 100, 20);
lblOldRate.setBounds(670, 125, 100, 20);
lblOldAmt.setBounds(770, 125, 100, 20);
frmOldItemInvoice.add(lblOldSn1);
frmOldItemInvoice.add(lblOldSn2);
frmOldItemInvoice.add(lblOldSn3);
frmOldItemInvoice.add(lblOldSn4);
frmOldItemInvoice.add(lblOldSn5);
frmOldItemInvoice.add(lblOldSn6);
frmOldItemInvoice.add(lblOldSn7);
frmOldItemInvoice.add(lblOldSn8);
frmOldItemInvoice.add(lblOldSn9);
frmOldItemInvoice.add(lblOldSn10);
frmOldItemInvoice.add(lblOldSno);
frmOldItemInvoice.add(lblOldItemType);
frmOldItemInvoice.add(lblOldDesc);
frmOldItemInvoice.add(lblOldPurity);
frmOldItemInvoice.add(lblOldWgt);
frmOldItemInvoice.add(lblOldRate);
frmOldItemInvoice.add(lblOldAmt);
frmOldItemInvoice.setSize(1000,550);
frmOldItemInvoice.setVisible(true);
frmOldItemInvoice.repaint();
}
}
期望的结果
实际结果
这些是输出窗口..我想要第二个屏幕截图中的行。