
正文
java经典代码解读 java代码含义
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java线程的经典代码
package threadgroup;
class ThreadDemo3 extends Thread {
private String name;
private int delay;
public ThreadDemo3(String sname, int i_delay) {
name = sname;
delay = i_delay;
}
public void run() {
try {
sleep(delay);
} catch (InterruptedException e) {
}
System.out.println("多线程测试!\n" + name + "\n" + delay);
}
}
public class testMyThread {
public static void main(String[] args) {
ThreadDemo3 th1,th2,th3;
th1 = new ThreadDemo3("线程1", (int) (Math.random() * 900));
th2 = new ThreadDemo3("线程2", (int) (Math.random() * 900));
th3 = new ThreadDemo3("线程3", (int) (Math.random() * 900));
th1.start();
th2.start();
th3.start();
}
}
package threadgroup;
public class threadDemo {
public static void main(String[] args) {
Thread t = Thread.currentThread();
t.setName("你好吗?");
System.out.println("正在进行的Thread是:" + t);
try {
for (int i = 0; i 5; i++) {
System.out.println("我不叫穆继超" + i);
Thread.sleep(3000);
}
} catch (Exception e) {
// TODO: handle exception
System.out.println("Thread has wrong" + e.getMessage());
}
}
}
package threadgroup;
public class threadDemo2 implements Runnable {
public threadDemo2() {
Thread t1 = Thread.currentThread();
t1.setName("第一个主进程");
System.out.println("正在运行" + t1);
Thread t2 = new Thread(this, "");
System.out.println("在创建一个进程");
t2.start();
try {
System.out.println("使他进入第一个睡眠状态");
Thread.sleep(2000);
} catch (InterruptedException e) {
System.out.println("Thread has wrong" + e.getMessage());
}
System.out.println("退出第一个进程");
}
public void run() {
try {
for (int i = 0; i 5; i++) {
System.out.println("进程" + i);
Thread.sleep(3000);
}
} catch (InterruptedException e) {
// TODO: handle exception
System.out.println("Thread has wrong" + e.getMessage());
}
System.out.println("退出第二个进程");
}
public static void main(String[] args) {
new threadDemo2();
}
}
相关问答
Q1: 请Java高手帮我解释一下这段代码,谢谢了
for(Student st : students)
System.out.println(st.toString());
这相当于一个foreach语句~是jdk1.5以上的版本才有的
相当于
for(int i=0;istudents.size();i++){
Student st = (Student)students.get(i);
System.out.println(st.toString());
}
或者用迭代其也可以实现:
Iterator it = students.iterator();
while(it.hasNext()){
Student st = (Student)it.next();
System.out.println(st);
}
Q2: 谁能帮我解读这段 java代码
帮java经典代码解读你加了注释java经典代码解读,看不看得懂要看你自己
public void hao() {
table.getTableHeader().setReorderingAllowed(false);//设置用户是否可以拖动列头,以重新排序各列。
table.getTableHeader().setResizingAllowed(false);//设置用户是否可以通过在头间拖动来调整各列的大小。
table.setEnabled(false);//设置是否启用此组件。
TableColumn column = null;
for (int i = 0; i 7; i++) { //设置列宽为60
column = table.getColumnModel().getColumn(i);
column.setPreferredWidth(60);
}
DefaultTableCellRenderer tcr = new DefaultTableCellRenderer() { //自定义绘制表格内容的方式
@Override
//table就是你要绘制的表格,value是单元格的值,isSelected表示表格单元格是否选中,hasFocus表示单元格是否有焦点,row表示单元格是第几行
//column表示单元格处于第几列
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if ((column == 0) || column == 6) {
setBackground(Color.red);//这里设置第0列和第六列的单元格背景色为红色
} else {
setBackground(Color.white); //其java经典代码解读他单元格设为白色
}
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
};
for (int i = 0; i 7; i++) {
table.getColumn(name[i]).setCellRenderer(tcr);//这里设置上面定义好的绘制单元格的类
}
}
Q3: java代码解读
第一个if是判断searchkey是不是空的,如果不是空的,就追加到name字段作为查询条件,like模糊查询
接着第二个if判断如果status的值不为空,就追加到status作为条件
如果status为空,走else分支,从userContext中获取到employee对象,接着判断,如果它的角色不是manager的话
把这个对象的id拿出来,作为seller.Id的条件进行查询
关于java经典代码解读和java代码含义的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。








