在java的swing中,一个jframe加入两左右个jpanel,左边画出一个图片,右边加入几个复选框和文本框。
求实例,不用特别详细,的代码,右边几个组件用几个jbutton就行。分数点很高,别糊弄,理论上我也会写代码,不过效果出不来,麻烦你写完测试一下,截个图,最好是myecil...
求实例,不用特别详细,的代码,右边几个组件用几个jbutton就行。
分数点很高,别糊弄,理论上我也会写代码,不过效果出不来,麻烦你写完测试一下,截个图,最好是myecilips做的。
谢谢了
左边的jpanel占4/5,右边的jpanel占1/5 展开
分数点很高,别糊弄,理论上我也会写代码,不过效果出不来,麻烦你写完测试一下,截个图,最好是myecilips做的。
谢谢了
左边的jpanel占4/5,右边的jpanel占1/5 展开
1个回答
展开全部
还有什么要求可以再说
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class MainFrame extends JFrame{
private ImagePanel leftPanel = new ImagePanel();
private JPanel rightPanel = new JPanel();
private JTextArea jtext = new JTextArea();
private JButton btnLoad = new JButton("Load"),
btnExit = new JButton("Exit");
public MainFrame() {
super("Demo");
//////
leftPanel.setPreferredSize(new Dimension(400, 300));
leftPanel.setIgnoreRepaint(true);
/////
rightPanel.setPreferredSize(new Dimension(100, 300));
rightPanel.setLayout(null);
jtext.setBounds(10, 90, 80, 24);
btnLoad.setBounds(10, 140, 80, 30);
btnExit.setBounds(10, 190, 80, 30);
btnLoad.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Image image = ImageIO.read(new File(jtext.getText()));
leftPanel.paintImage(image);
} catch (Exception e1) {
JOptionPane.showMessageDialog(null, "Image open error!");
}
}
});
btnExit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
rightPanel.add(jtext);
rightPanel.add(btnLoad);
rightPanel.add(btnExit);
/////
this.setLayout(new BorderLayout());
this.add(leftPanel, BorderLayout.CENTER);
this.add(rightPanel, BorderLayout.EAST);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack();
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setVisible(true);
}
public static void main(String[] args) {
new MainFrame();
}
class ImagePanel extends JPanel {
private Image image = null;
public void paintImage(Image image) {
this.image = image;
this.repaint();
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), null);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询