⽰例7:练习-SplitPanel 设计⼀个像的左右风格的SplitPanel
左边放3个按钮,上⾯的⽂字分别是: 盖伦,提莫,安妮
右边默认显⽰盖伦
当左边按钮点击的时候,右边就会显⽰对应的图⽚
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import l.TextField;
public class CheckBox {
public static void main(String[] args){
JFrame f = new JFrame("CardLayerout");
f.setSize(300, 400);
f.setLocation(300,300);
JPanel p1 = new JPanel();
p1.setBounds(50,50,300,60);
JButton b1 = new JButton("杰杰");
JButton b2 = new JButton("海⾥");
JButton b3 = new JButton("主见");javaswing和javafx
p1.add(b1);
p1.add(b2);
p1.add(b3);
JPanel p2 = new JPanel();
p2.setBounds(10,150,300,60);
JLabel l = new JLabel();
b1.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
ImageIcon i = new ImageIcon("d:/迅雷下载/shana.png");
l.setIcon(i);
}
});
b2.addActionListener(new ActionListener(){
@Override
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
ImageIcon i2 = new ImageIcon("d:/迅雷下载/shana_heiheihei.png");
l.setIcon(i2);
}
});
b3.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
ImageIcon i3 = new ImageIcon("d:/迅雷下载/五年计划.png");
l.setIcon(i3);
}
});
p2.add(l);
JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, p1, p2);  sp.setDividerLocation(80);
f.add(sp);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。