java写代码的图片 java制作图片

帮我看一下,我的java代码 。为什么运行结果不对!如图:请详解 , 为什么其他组件没有显示?看注释java写代码的图片:
import java.awt.GridLayout;
import javax.swing.*;
public class LoadForm extends JFrame{
private JPanel jpanel1;
private JTextField jtext1;
private JPasswordField password;
private JLabel jlable1;
private JLabel jlable2;
private JButton button1;
private JButton button2;
public LoadForm()
{
super("商品管理系统");
this.setLayout(null);
GridLayout layout=new GridLayout(3,3,10,10);//这句保留
jpanel1=new JPanel();
//jpanel1.setLayout(null);//jpanel1java写代码的图片的布局不能为空
jlable1=new JLabel("用户名");
jlable2=new JLabel("密码");
jtext1=new JTextField();
password=new JPasswordField();
button1=new JButton("确定");
button2=new JButton("取消");
jpanel1.add(jlable1);
jpanel1.add(jtext1);
jpanel1.add(jlable2);
jpanel1.add(password);
jpanel1.add(button1);
jpanel1.add(button2);
【java写代码的图片 java制作图片】//this.add(jpanel1);//写法错误
this.setContentPane(jpanel1);//设置jpanel1为Framejava写代码的图片的内容面版
this.setBounds(200,200,100,100);
//this.setSize(200,200);
this.setVisible(true);
}
//main方法测试
public static void main(String args[]){
new LoadForm();
}
}
求大神帮写一下完整的java代码 。题目要求见图片所示 。在线等!import java.util.Vector;
class User {
String name;
public User(String name) {
this.name = name;
}
public String toString() {
return name;
}
}
public class UserManager {
VectorUser v;
public UserManager() {
this.v = new VectorUser();
}
boolean addUser(User u) {
return v.add(u);
}
boolean removeUser(User u) {
return v.remove(u);
}
boolean existUser(User u) {
return v.contains(u);
}
void showAllUser() {
for (int i = 0; iv.size(); i) {
System.out.print(v.get(i)"\t");
}
System.out.println();//换行
}
//main方法可以删除,主要用于测试
public static void main(String[] args) {
User u1 = new User("天涯");
User u2 = new User("明月");
User u3 = new User("孙悟空");
UserManager um = new UserManager();
um.addUser(u1);//增加用户
um.addUser(u2);
um.addUser(u3);
um.showAllUser();//显示所有java写代码的图片的用户
um.removeUser(u2);//删除 用户 明月
um.showAllUser();
if(um.existUser(u1)){
System.out.println("用户" u1 "存在");
}else{
System.out.println("用户" u1 "不存在");
}
User u0 = new User("哈哈");
System.out.println(um.existUser(u0));//是否存在用户哈哈 ,在管理用户java写代码的图片的 类里
}
}
输出
天涯 明月 孙悟空
天涯 孙悟空
用户天涯存在
false
在java 中在代码中要引用的图片该放在哪个文件?放到任意文件夹都可以java写代码的图片 , 看java写代码的图片你的管理方式 。
1、放到和程序目录下的某个文件夹中 。
// 假设图片放到程序运行目录的img目录下
BufferedImage img = ImageIO.read(new File("img/my.png"));
2、放到源文件中,和读取类在同一目录,使用时图片要按包名打包到jar中
// 假设图片放到src下,和MyImages在一个目录
BufferedImage img = ImageIO.read(MyImages.class.getResource("my.png"));
3、放到源文件中 , 但在独立文件夹中,使用时图片要按包名打包到jar中
// 假设图片放到src下的img目录中
BufferedImage img = ImageIO.read(MyImages.class.getResource("res/my.png"));
如图,如何用Java代码写?Java程序:
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Exercise12_10 extends JFrame {
private static final long serialVersionUID = 1L;
private CanvasPanel pnlCanvas = null;
public Exercise12_10(){
super("Exercise12_10");
pnlCanvas = new CanvasPanel();
this.add(pnlCanvas);
this.setSize(250, 250);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Exercise12_10();
}
}
class CanvasPanel extends JPanel{
private static final long serialVersionUID = 1L;
public void paint(Graphics g){
int W = this.getWidth();
int H = this.getHeight();
int i, j;
int width = W / 8;
int height = H / 8;
int x, y;
for(i=0; i9; i){
for(j=0; j8; j){
x = j * width;
y = i * height;
if((i j)%2 == 0){//画矩形
g.drawRect(x, y, width, height);
}
else{//填充矩形
g.fillRect(x, y, width, height);
}
}
}
}
}
运行结果如图所示:
关于java写代码的图片和java制作图片的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读