满意答案
huangxr423
2015.04.23
采纳率:46% 等级:8
已帮助:814人
这样可以么123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener; import javax.swing.ButtonGroup;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JRadioButton;import javax.swing.Timer; public class MainFrame extends JFrame implements ActionListener{ private ButtonGroup bg = new ButtonGroup(); private ProccessControl lightPanel = new ProccessControl(0); private JRadioButton mode_1 = new JRadioButton("MODE 1"), mode_2 = new JRadioButton("MODE 2"); public MainFrame() { super("Signal Light"); this.setSize(new Dimension(300, 300)); this.setLayout(null); lightPanel.setBounds(50, 10, 80, 240); mode_1.setBounds(150, 75, 80, 50); mode_2.setBounds(150, 125, 80, 50); mode_1.addActionListener(this); mode_2.addActionListener(this); bg.add(mode_1); bg.add(mode_2); mode_1.setSelected(true); this.add(lightPanel); this.add(mode_1); this.add(mode_2); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); this.setResizable(false); this.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { if (e.getSource().equals(mode_1)) { lightPanel.setControlMode(0); } else { lightPanel.setControlMode(1); } } public static void main(String[] args) { new MainFrame(); } } class ProccessControl extends JPanel implements ActionListener{ private SignalLight[] light = new SignalLight[3]; private int controlMode; private Timer timer = new Timer(1000, this); private final Color[][] color = { {Color.GREEN, Color.YELLOW, Color.RED}, {Color.RED, Color.YELLOW, Color.GREEN} }; private int currentLight; public ProccessControl(int controlMode) { this.setControlMode(controlMode); this.setOpaque(true); this.setLayout(new GridLayout(3, 1)); for(int i = 0; i
00分享举报