1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| public class Mpanel extends JPanel {
public JButton bouton1 = new JButton("Today's articles");
public JButton bouton2 = new JButton("Articles List");
public JButton bouton3 = new JButton("Software Infos");
public JPanel inter = new JPanel();
public InfoPanel info = new InfoPanel();
public TodayArticles today = new TodayArticles();
public ArticleList list = new ArticleList();
public CardLayout cl = new CardLayout();
String [] listContent = {"list", "info", "today"};
public JPanel content = new JPanel();
public Mpanel() {
this.setBackground(Color.white);
inter.add(Box.createRigidArea(new Dimension(-10 , 300)));
bouton1.setPreferredSize(new Dimension(225, 35));
bouton2.setPreferredSize(new Dimension(225, 35));
bouton3.setPreferredSize(new Dimension(225, 35));
inter.add(bouton1);
inter.add(bouton2);
inter.add(bouton3);
inter.setBackground(new Color(0, 0, 0, 0));
this.add(inter);
content.setLayout(cl);
content.add(today, listContent[0]);
content.add(list, listContent[1]);
content.add(info, listContent[2]);
bouton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event){
cl.show(content, listContent[0]);
}
});
bouton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event){
cl.show(content, listContent[1]);
}
});
bouton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event){
cl.show(content, listContent[2]);
}
});
this.add(content);
}
public void paintComponent (Graphics g){
try{
Image logo = ImageIO.read (Img.class.getResource("logo.png"));
g.drawImage(logo, this.getWidth() / 2 - 687 / 2, 10, 687, 121, this);
}catch (IOException e){
e.printStackTrace();
}
}
} |
Partager