62,628
社区成员
发帖
与我相关
我的任务
分享package cjco;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.LinkedList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.UIManager;
/**
* Java中CardLayout布局管理器使用的小例子
*/
public class Test0 extends JFrame implements ActionListener, Runnable {
/**
*
*/
private static final long serialVersionUID = 1L;
public ArrayList<JTextArea> al = new ArrayList<JTextArea>();
private JPanel pane = null; // 主要的JPanel,该JPanel的布局管理将被设置成CardLayout
private JPanel p = null; // 放按钮的JPanel
private CardLayout card = null; // CardLayout布局管理器
private JButton button_1 = null; // 上一步
private JButton button_2 = null; // 下一步
public LinkedList<JTextArea> ld = new LinkedList<JTextArea>();
public Test0(String str,int pagenum) {
super("CardLayout Test");
int myLocalPagenum = CalcMyPage.counter(str);
card = new CardLayout(5, 5);
pane = new JPanel(card);
// String[] buffer = str.split("丮");
// int pagenum = Integer.parseInt(buffer[0]);
// str = buffer[1];
this.setResizable(false);
if(myLocalPagenum!=0){
for(int i = 0;i<myLocalPagenum;i++){
JPanel jp = new JPanel();
JTextArea jta0 = new JTextArea();
jta0.setSize(332, 722);
jta0.setText("CJCO");
jta0.setLineWrap(true);
jta0.setSize(303, 700);
jta0.setBackground(Color.RED);
ld.add(jta0);
jp.add(jta0);
pane.add(jp,"CJCO");
this.add(pane);
}}else{
myLocalPagenum = 1;
for(int i = 0;i<myLocalPagenum;i++){
JPanel jp = new JPanel();
JTextArea jta0 = new JTextArea();
jta0.setBackground(Color.RED);
jta0.setSize(332, 722);
jta0.setText(CalcMyPage.ld0.get(i));
jta0.setLineWrap(true);
jta0.setSize(303, 700);
jta0.setBackground(Color.RED);
ld.add(jta0);
jp.add(jta0);
pane.add(jp,"CJCO");
this.add(pane);
}
}
try {
// 将LookAndFeel设置成Windows样式
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception ex) {
ex.printStackTrace();
}
/**创建一个具有指定的水平和垂直间隙的新卡片布局*/
card = new CardLayout(5, 5);
pane = new JPanel(card); // JPanel的布局管理将被设置成CardLayout
p = new JPanel(); // 构造放按钮的JPanel
button_1 = new JButton("< 上一步");
button_2 = new JButton("下一步 >");
p.add(button_1);
p.add(button_2);
/**下面是翻转到卡片布局的某个组件,可参考API中的文档*/
button_1.addActionListener(new ActionListener(){ // 上一步的按钮动作
public void actionPerformed(ActionEvent e) {
card.previous(pane);
}
});
button_2.addActionListener(new ActionListener(){ // 下一步的按钮动作
public void actionPerformed(ActionEvent e) {
card.next(pane);
}
});
this.getContentPane().add(pane);
this.getContentPane().add(p, BorderLayout.SOUTH);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setSize(332, 722);
}
public void run(){
this.setVisible(true);
}
public static void main(String[] args) {
Test0 m = new Test0("加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油",9);
Thread obj = new Thread(m);
obj.start();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}package cjco;
import java.util.LinkedList;
public class CalcMyPage {
static LinkedList<String> ld = new LinkedList<String>();
static LinkedList<String> ld0 = new LinkedList<String>();
int[] mystrIndex = new int[43000];
StringBuilder buld = null;
public CalcMyPage(String str){
System.out.println("进行行数统计之前"+counter(str));
int linenum = counter(str);
for(int i =0;i<linenum;i++){
System.out.println(ld0.get(i));
}
System.out.println(linenum);
}
public static int counter(String str){
int H=0,index,i = 0;
String str0 = "";
while(str.indexOf("\n")!=-1||str.length()>25){
if((index=str.indexOf("\n"))<25&&index>0){
H++;
str = str.substring(index+1,str.length());
String str1 = str.substring(0,index+1);
ld.add(str1);
}else if(index == -1){
H++;
str = str.substring(26,str.length());
String str1 = "";
try{
str1 = str.substring(0,26);
}catch(StringIndexOutOfBoundsException e){
}
ld.add(str1);
}
else{
H++;
str = str.substring(26,str.length());
String str1 = str.substring(0,26);
ld.add(str1);
}
str0 = str0+ld.get(i);
i++;
if(H%42==0||H<42){
ld0.add(str0);
}
}
return ld0.size();
}
}





也求CSDN路过的高手,能够不吝赐教!!!!!package c_port_packageBJTeacher;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.LinkedList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.UIManager;
/**
* Java中CardLayout布局管理器使用的小例子
*/
public class MyChatLogFrame extends JFrame implements ActionListener, Runnable {
/**
*
*/
private static final long serialVersionUID = 1L;
public ArrayList<JTextArea> al = new ArrayList<JTextArea>();
private JPanel pane = null; // 主要的JPanel,该JPanel的布局管理将被设置成CardLayout
private JPanel p = null; // 放按钮的JPanel
private CardLayout card = null; // CardLayout布局管理器
private JButton button_1 = null; // 上一步
private JButton button_2 = null; // 下一步
public LinkedList<JTextArea> ld = new LinkedList<JTextArea>();
public MyChatLogFrame(String str,int pagenum) {
super("CardLayout Test");
int myLocalPagenum = pagenum;
card = new CardLayout(5, 5);
pane = new JPanel(card);
// String[] buffer = str.split("丮");
// int pagenum = Integer.parseInt(buffer[0]);
// str = buffer[1];
this.setResizable(false);
if(myLocalPagenum!=0){
for(int i = 0;i<myLocalPagenum;i++){
JPanel jp = new JPanel();
jp.setBackground(Color.RED);
JTextArea jta0 = new JTextArea();
jta0.setSize(332, 722);
jta0.setText("CJCO");
jta0.setLineWrap(true);
jta0.setSize(303, 700);
jta0.setBackground(Color.RED);
ld.add(jta0);
jp.add(jta0);
pane.add(jp,"CJCO");
this.add(pane);
}}else{
myLocalPagenum = 1;
for(int i = 0;i<myLocalPagenum;i++){
JPanel jp = new JPanel();
JTextArea jta0 = new JTextArea();
jta0.setBackground(Color.RED);
jta0.setSize(332, 722);
jta0.setText(CalcMyPage.ld0.get(i));
jta0.setLineWrap(true);
jta0.setSize(303, 700);
jta0.setBackground(Color.RED);
ld.add(jta0);
jp.add(jta0);
pane.add(jp,"CJCO");
this.add(pane);
}
}
try {
// 将LookAndFeel设置成Windows样式
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception ex) {
ex.printStackTrace();
}
/**创建一个具有指定的水平和垂直间隙的新卡片布局*/
card = new CardLayout(5, 5);
pane = new JPanel(card); // JPanel的布局管理将被设置成CardLayout
p = new JPanel(); // 构造放按钮的JPanel
button_1 = new JButton("< 上一步");
button_2 = new JButton("下一步 >");
p.add(button_1);
p.add(button_2);
/**下面是翻转到卡片布局的某个组件,可参考API中的文档*/
button_1.addActionListener(new ActionListener(){ // 上一步的按钮动作
public void actionPerformed(ActionEvent e) {
card.previous(pane);
}
});
button_2.addActionListener(new ActionListener(){ // 下一步的按钮动作
public void actionPerformed(ActionEvent e) {
card.next(pane);
}
});
this.getContentPane().add(pane,BorderLayout.NORTH);
this.getContentPane().add(p, BorderLayout.SOUTH);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setSize(332, 722);
}
public void run(){
this.setVisible(true);
}
public static void main(String[] args) {
MyChatLogFrame m = new MyChatLogFrame("加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油加油",2);
Thread obj = new Thread(m);
obj.start();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
希望得到二位祖师爷的点拨:
小弟的这个JFrame窗口,怎么修改,能够让小弟,可以通过第40行到第54行的循环语句进行”多个第41行的JPanel页面实例的创建“,让小弟的用户,能够通过”上一步“与”下一步“两个按钮的翻页,进行自己的服务器推送的信息的"即时浏览"”,并且能够通过JPanel的实例jp上的jta0,这个JTextArea的实例进行自己的用户的“浏览数据需求”的直接满足.
希望得到二位祖师爷:
跋陀大哥,张三丰大哥的亲自技艺传授!!!!
小弟行不更名,坐不改姓:
苏乞儿!!是也!!!!!

[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/001/face/83.gif][img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/001/face/83.gif][img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/001/face/83.gif]


楼主:
修改Test0这个类:
1.将你程序96行:改为 this.getContentPane().add(pane,BorderLayout.NORTH);
2.将你程序48行:改为 jp.setBackground(Color.RED);
3.将你程序46行:改为 jta0.setLineWrap(false);或者直接注释掉,要不然不会居中;[/quote]
不是指导,是帮顶哈,java我还真是一窍不通的
楼主:
修改Test0这个类:
1.将你程序96行:改为 this.getContentPane().add(pane,BorderLayout.NORTH);
2.将你程序48行:改为 jp.setBackground(Color.RED);
3.将你程序46行:改为 jta0.setLineWrap(false);或者直接注释掉,要不然不会居中;
帮你顶一下