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 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
public class Mpanel extends JPanel {
public static void main(String[] args) {
final JFrame f = new JFrame("Test ");
f.add(new Mpanel(), BorderLayout.CENTER);
f.setSize(800, 600);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
f.setVisible(true);
}
});
}
private static final long serialVersionUID = 1L;
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.setLayout(new BorderLayout());
this.setBackground(Color.white);
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));
content.setLayout(cl);
content.add(today, listContent[0]);
content.add(list, listContent[1]);
content.add(info, listContent[2]);
bouton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event){
cl.show(content, listContent[0]);
}
});
bouton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event){
cl.show(content, listContent[1]);
}
});
bouton3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event){
cl.show(content, listContent[2]);
}
});
this.add(inter,BorderLayout.NORTH);
this.add(content, BorderLayout.CENTER);
}
} |
Partager