在加拿大
已解决,虽然没有成功的将2、3、4整合,但是成功的将1、2、3、4都整合了。。。首先我要做个这样的窗口:
然后最下面一行按钮点击每一个都会有相应的对话框出来,比如点击supprimer按钮会出来这样的对话框:
我现在已经已经完成了这些窗口,拿成功叫出supprimer为例子:1. classePrincipale:public class InterfacePrincipale extends JFrame{ //declaration des attribus... public InterfacePrincipale() { super("Nordic Pneus - Système de Gestion de l'Inventaire (SGI)"); init(); } public static void main(String[] args) { JFrame fenetre = new InterfacePrincipale(); fenetre.setBounds(400, 300, 600, 400); fenetre.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); fenetre.setVisible(true); } private void init() { //分别构建上中下等panel。。。 //Mettre des ecouteurs sur les boutons. Ecouteur ecouteur = new Ecouteur(); bouttonSupprimer.setActionCommand("supprimer"); bouttonSupprimer.addActionListener(ecouteur); 。。。 } //classe interne d'Ecouteur private class Ecouteur implements ActionListener { DialogSupprimerPneus supprimerDialog; if (evt.getActionCommand().equals("supprimer")){ supprimerDialog = new DialogSupprimerPneus(); supprimerDialog.setVisible(true); }}2. classe DialogSupprimerPneus:package tp3.interfacegraphiques;import java.awt.GridLayout;import javax.swing.JDialog;@SuppressWarnings("serial")public class DialogSupprimerPneus extends JDialog{ private PanneauSupprimerInfo panneauInfo; private PanneauSupprimerBoutton panneauBoutton; public DialogSupprimerPneus() { this.setTitle("Nordic Pneus (SGI) - Suppression"); panneauInfo = new PanneauSupprimerInfo(); panneauBoutton = new PanneauSupprimerBoutton(); this.setLayout(new GridLayout(2,1, 5, 5)); this.add(panneauInfo); this.add(panneauBoutton); setBounds(400, 300, 600, 250); }}3. classe PanneauSupprimerBoutton:package tp3.interfacegraphiques;import java.awt.FlowLayout;import javax.swing.JButton;import javax.swing.JPanel;@SuppressWarnings("serial")public class PanneauSupprimerBoutton extends JPanel{ private JButton annuler; private JButton supprimer; PanneauSupprimerBoutton(){ init(); } private void init(){ annuler = new JButton("Annuler"); supprimer = new JButton("Supprimer"); this.setLayout(new FlowLayout(FlowLayout.RIGHT)); this.add(supprimer); this.add(annuler); }}4. classe PanneauSupprimerInfo:package tp3.interfacegraphiques;import java.awt.GridLayout;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.border.TitledBorder;@SuppressWarnings("serial")public class PanneauSupprimerInfo extends JPanel{ private JLabel descrip; private JLabel nbPneus; private JTextField textDescrip; private JTextField textNbPneus; PanneauSupprimerInfo(){ init(); } private void init(){ this.setBorder(new TitledBorder(null, "Information du pneu", TitledBorder.LEADING, TitledBorder.TOP, null, null)); this.setLayout(new GridLayout(2, 2, 10, 4)); descrip = new JLabel("Description:"); nbPneus = new JLabel("Nombre de pneus:"); textDescrip = new JTextField(); textNbPneus = new JTextField(); this.add(descrip); this.add(textDescrip); this.add(nbPneus); this.add(textNbPneus); textDescrip.setEditable(false); }}我现在的问题是想把2、3、4三个class整合到一个class里面,可是老是出现nullPointerException:
我的整合方法如下:package tp3.interfacegraphiques;import java.awt.FlowLayout;import java.awt.GridLayout;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.border.TitledBorder;@SuppressWarnings("serial")public class DialogSupprimerPneus extends JDialog{ private JPanel panneauInfo; private JLabel descrip; private JLabel nbPneus; private JTextField textDescrip; private JTextField textNbPneus; private JPanel panneauBoutton; private JButton annuler; private JButton supprimer; public DialogSupprimerPneus() { init(); } private void init(){ panneauInfo.setBorder(new TitledBorder(null, "Information du pneu", TitledBorder.LEADING, TitledBorder.TOP, null, null)); panneauInfo.setLayout(new GridLayout(2, 2, 10, 4)); descrip = new JLabel("Description:"); nbPneus = new JLabel("Nombre de pneus:"); textDescrip = new JTextField(); textNbPneus = new JTextField(); panneauInfo.add(descrip); panneauInfo.add(textDescrip); panneauInfo.add(nbPneus); panneauInfo.add(textNbPneus); textDescrip.setEditable(false); annuler = new JButton("Annuler"); supprimer = new JButton("Supprimer"); panneauBoutton.setLayout(new FlowLayout(FlowLayout.RIGHT)); panneauBoutton.add(supprimer); panneauBoutton.add(annuler); this.setTitle("Nordic Pneus (SGI) - Suppression"); this.setLayout(new GridLayout(2,1, 5, 5)); this.add(panneauInfo); this.add(panneauBoutton); setBounds(400, 300, 600, 250); }}请问是哪里出了问题导致的呢?谢谢!
·加拿大新闻 她是流行天后,他是前总理:为何凯蒂·佩里与杜鲁多能走到一
·加拿大新闻 未来一周加拿大商界须关注之大事
·加拿大新闻 温哥华王宅地库执到宝乾隆珍藏墨宝多伦多拍卖108万加元成交
·加拿大新闻 日产天籁·鸿蒙座舱四季度全球首发,新科技驾享体验
·加拿大新闻 [有片] 万锦入屋行劫未遂 警车迎头撞截贼车
·汽车 轮胎选择
·汽车 皇冠混合动力电池更换成本