贴吧用户_0JAM9W5 332802774
关注数: 20 粉丝数: 30 发帖数: 870 关注贴吧数: 9
新人求助啊 这个程序我想修改button3的位置改成竖着2个横着2个的。。求大神帮忙啊。。。 package awt.button; import java.awt.Component; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.UnsupportedLookAndFeelException; import awt.beibao.PackageIssue; import awt.digui.HannoiWindow; import awt.mi.Maze; import awt.queen.Queen2; public class AWTex { public static void main(String[] args) { // TODO Auto-generated method stub new AWTex().rn(); } public void rn(){ JFrame frame = new JFrame("递归算法的动态演示-南通大学-刘璐"); JButton button1 = new JButton("N后问题"); JButton button2 = new JButton("背包问题"); JButton button3 = new JButton("汉诺塔问题"); JButton button4 = new JButton("迷宫问题"); button1.addActionListener(new myClickListener1()); button2.addActionListener(new myClickListener2()); button3.addActionListener(new myClickListener3()); button4.addActionListener(new myClickListener4()); JPanel imagePanel; ImageIcon background; URL url1 = Bf.class.getResource("367701.jpg"); background = new ImageIcon(url1);// 背景图片 JLabel label = new JLabel(background);// 把背景图片显示在一个标签里面 // 把标签的大小位置设置为图片刚好填充整个面板 label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight()); // 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明 imagePanel = (JPanel) frame.getContentPane(); imagePanel.setOpaque(false); // 内容窗格默认的布局管理器为BorderLayout imagePanel.setLayout(new FlowLayout()); imagePanel.add(button1); imagePanel.add(button2); imagePanel.add(button3); button3.setBounds(300,200,600,500); imagePanel.add(button4); frame.getLayeredPane().setLayout(null); // 把背景图片添加到分层窗格的最底层作为背景 frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //frame.setSize(background.getIconWidth(), background.getIconHeight()); frame.setResizable(false); frame.setVisible(true); frame.setBounds(300,100,background.getIconWidth(), background.getIconHeight()); } private void setVisible(boolean b) { // TODO Auto-generated method stub } private class myClickListener1 implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub new Queen2().begin(); } } private class myClickListener2 implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub try { new PackageIssue().begin(); } catch (ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (InstantiationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IllegalAccessException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (UnsupportedLookAndFeelException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } private class myClickListener3 implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub HannoiWindow.begin(); } private void setBounds(int i, int j, int k, int l) { // TODO Auto-generated method stub } } private class myClickListener4 implements ActionListener{ @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub Maze.begin(); } } }
1 下一页