我上个月在J2ME聊天应用上工作。但是坚持上个月的消息。我还在评论中添加了消息屏幕的屏幕截图。
我的应用场景如下所述。
我有一个名为 conservationForm 的表单,带有边框布局。在主要形式中,我进一步添加了两个容器, msgPane , boxlayout ,其他 inputPane , flowlayout 。 msgPane 包含来自收件人和发件人的所有邮件。每个完整的消息都以msgpane的形式附加在名为 myContainer 的容器中。 myContainer 包含标签形式的文字和图片,我已将其附加在 myContainer 中。
我已经尝试了所有可能的选择,但我的所有努力都浪费了,没有取得任何成果。提前感谢您的任何帮助。
我在j2me和lwuit的技能水平是初学者。我正在寻求J2ME和lwuit专家的帮助。
我也在下面粘贴我的会话密码。
public void /*@Shah Displayable */ getGuiConversation(String msgText) {
final Form conservationForm = new Form(currentRoster.jid.getNickname());
boolean canAnswer = currentConversation.canAnswer();
conservationForm.setScrollable(false);
//conservationForm.repaint(); commented on 26-05-15
conservationForm.setLayout(new BorderLayout());
conservationForm.setUnselectedStyle(mainFormStyling());
conservationForm.setTitleStyle(formHeaderStyle());
conservationForm.setMenuStyle(formFooterStyle());
Image icon, emoticonIcon, attachmentIcon;
Button emoticonBtn, attachmentBtn;
int strLen = (int) (Display.getInstance().getDisplayWidth()/16);
final Container emoticonPanel = new Container(new FlowLayout());
final Container msgPane = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Container inputPane = new Container(new FlowLayout());
Style inputPaneUStyle = new Style();
Style inputPaneSStyle = new Style();
inputPaneUStyle.setMargin(0,0,0,0);
inputPaneUStyle.setBgColor(util.guiClass.ButtonBgColor);
inputPaneUStyle.setFgColor(util.guiClass.ButtonBgColor);
inputPaneSStyle.setMargin(0,0,2,2);
inputPaneSStyle.setBgColor(util.guiClass.ButtonBgColor);
inputPaneSStyle.setFgColor(util.guiClass.ButtonBgColor);
inputPane.setUnselectedStyle(inputPaneUStyle);
inputPane.setSelectedStyle(inputPaneSStyle);
inputPane.setPreferredH(60);
try {
currentConversation.messages= Datas.getMessage(currentConversation.name);
} catch (RecordStoreException ex) {
}
try {
icon = Image.createImage("/res/smile.png").scaled(14, 14);
attachmentIcon = Image.createImage("/res/attach-icon.png").scaled(14, 14);
}catch(java.io.IOException e){
icon = attachmentIcon = null;
}
emoticonBtn = new Button(icon);
attachmentBtn = new Button(attachmentIcon);
attachmentBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
showFiles();
}
});
Vector msgs = currentConversation.messages;
Message msg;
Container myContainer = null;
Emotions em = new Emotions();
for (int i=0; i<msgs.size(); i++) {
msg = (Message) msgs.elementAt(i);
String msgString="";
if(msg.from.equals(currentConversation.name)){
myContainer = new Container(new FlowLayout());
Style myContainerUStyle = new Style();
Style myContainerSStyle = new Style();
myContainerUStyle.setBgColor(0x75b0d2);
myContainerUStyle.setFgColor(0x75b0d2);
myContainerUStyle.setPadding(1, 1, 1, 1);
myContainerUStyle.setMargin(5,5, 40, 5);
myContainerUStyle.setBorder(Border.createRoundBorder(12, 5, 0x75b0d2));
myContainerSStyle.setBgColor(0x007BC1);
myContainerSStyle.setFgColor(0x007BC1);
myContainerSStyle.setPadding(1, 1, 1, 1);
myContainerSStyle.setMargin(5,5, 40, 5);
myContainerSStyle.setBgTransparency(150);
myContainerSStyle.setBorder(Border.createRoundBorder(12, 5, 0x75b0d2));
myContainer.setUnselectedStyle(myContainerUStyle);
myContainer.setSelectedStyle(myContainerSStyle);
msgString = msg.getText().trim();
float count = msgString.length();
count = (count/strLen);
int pHeight = (int)(30*Math.ceil(count));
myContainer.setPreferredH(pHeight);
int pWidth = (int)((3/4)*Display.getInstance().getDisplayWidth());
myContainer.setPreferredW(pWidth);
String substr;
int index = -1;
for (int j = 0; j < Emotions.emoticonKeys.length; j++) {
index = msgString.indexOf(Emotions.emoticonKeys[j]);
if(index>-1)
break;
}
if(index>-1){
int k = 0;
String emotiID = "";
while(index>-1){
int currentIndex = -1;
for (int j = 0; j < Emotions.emoticonKeys.length; j++) {
index = msgString.indexOf(Emotions.emoticonKeys[j]);
if(index>-1){
if(currentIndex<0){
currentIndex = index;
}
if(index<=currentIndex){
currentIndex = index;
emotiID = Emotions.emoticonKeys[j];
}
}
}
substr = msgString.substring(0, currentIndex);
msgString = msgString.substring(currentIndex+emotiID.length());
Label lb;
Label emoticonLabel = new Label("");
try {
emoticonIcon = Image.createImage((String) util.Emotions.emoticonList.get(emotiID)).scaled(14, 14);
emoticonLabel = new Label(emoticonIcon);
} catch (IOException ex) {
}
emoticonLabel.getStyle().setMargin(0, 0, 0, 0);
emoticonLabel.getStyle().setBgColor(0x75b0d2);
if(substr.length()>emotiID.length()){
int strLength = substr.length();
while(strLength>0){
if(substr.length()>strLen){
lb= new Label(substr.substring(0, strLen));
substr = substr.substring(strLen);
strLength = substr.length();
}else {
lb= new Label(substr.substring(0));
strLength = 0;
}
lb.getStyle().setBgColor(0x75b0d2);
lb.getStyle().setMargin(0, 0, 0, 0);
myContainer.addComponent(lb);
}
}
myContainer.addComponent(emoticonLabel);
if(msgString.length()!= 0){
for (int j = 0; j < Emotions.emoticonKeys.length; j++) {
try{
index = msgString.indexOf(Emotions.emoticonKeys[j]);
}catch (Exception ex){
}
if(index>-1){
break;
}
}
if(index<0 && msgString.length()>(emotiID.length()-1)){
int strLength = msgString.length();
while(strLength>0){
if(msgString.length()>strLen){
lb= new Label(msgString.substring(0, strLen));
substr = msgString.substring(strLen);
strLength = msgString.length();
}else {
lb= new Label(msgString.substring(0));
strLength = 0;
}
lb.getStyle().setMargin(0, 0, 0, 0);
lb.getStyle().setBgColor(0x75b0d2);
myContainer.addComponent(lb);
}
}
}else {
index = -1;
}
}
}else {
int strLength = msgString.length();
while(strLength>-1){
Label lb;
if(msgString.length()>strLen){
lb= new Label(msgString.substring(0, strLen));
msgString = msgString.substring(strLen);
strLength = msgString.length();
}else {
lb= new Label(msgString.substring(0));
strLength = -1;
}
lb.getStyle().setMargin(0, 0, 0, 0);
lb.getStyle().setBgColor(0x75b0d2);
myContainer.addComponent(lb);
}
}
msgPane.addComponent(myContainer);
msgPane.setNextFocusDown(myContainer);
msgPane.setNextFocusUp(myContainer);
}else{
myContainer = new Container(new FlowLayout());
Style myContainerUStyle = new Style();
Style myContainerSStyle = new Style();
myContainerUStyle.setBgColor(0x6d96ad);
myContainerUStyle.setFgColor(0x6d96ad);
myContainerUStyle.setPadding(1, 1, 1, 1);
myContainerUStyle.setMargin(5,5, 5, 40);
myContainerUStyle.setBorder(Border.createRoundBorder(12, 5, 0x6d96ad));
myContainerSStyle.setBgColor(0x6d96ad);
myContainerSStyle.setFgColor(0x6d96ad);
myContainerSStyle.setPadding(1, 1, 1, 1);
myContainerSStyle.setMargin(5,5, 5, 40);
myContainerSStyle.setBgTransparency(150);
myContainerSStyle.setBorder(Border.createRoundBorder(12, 5, 0x6d96ad));
myContainer.setUnselectedStyle(myContainerUStyle);
myContainer.setSelectedStyle(myContainerSStyle);
msgString = msg.getText().trim();
float count = msgString.length();
count = (count/strLen);
int pHeight = (int)(30*Math.ceil(count));
myContainer.setPreferredH(pHeight);
int pWidth = (int)((3/4)*Display.getInstance().getDisplayWidth());
myContainer.setPreferredW(pWidth);
String substr;
int index = -1;
for (int j = 0; j < Emotions.emoticonKeys.length; j++) {
index = msgString.indexOf(Emotions.emoticonKeys[j]);
if(index>-1)
break;
}
if(index>-1){
String emotiID = "";
while(index>-1){
int currentIndex = -1;
for (int j = 0; j < Emotions.emoticonKeys.length; j++) {
index = msgString.indexOf(Emotions.emoticonKeys[j]);
if(index>-1){
if(currentIndex<0){
currentIndex = index;
}
if(index<=currentIndex){
currentIndex = index;
emotiID = Emotions.emoticonKeys[j];
}
}
}
substr = msgString.substring(0, currentIndex);
msgString = msgString.substring(currentIndex+emotiID.length());
Label lb;
Label emoticonLabel = new Label("");
try {
emoticonIcon = Image.createImage((String) util.Emotions.emoticonList.get(emotiID)).scaled(14, 14);
emoticonLabel = new Label(emoticonIcon);
} catch (IOException ex) {
}
emoticonLabel.getStyle().setBgColor(0x6d96ad);
if(substr.length()>emotiID.length()){
int strLength = substr.length();
while(strLength>0){
if(substr.length()>strLen){
lb= new Label(substr.substring(0,strLen));
substr = substr.substring(strLen);
strLength = substr.length();
}else {
lb= new Label(substr.substring(0));
strLength = 0;
}
lb.getStyle().setBgColor(0x6d96ad);
lb.getStyle().setMargin(0, 0, 0, 0);
myContainer.addComponent(lb);
}
}
emoticonLabel.getStyle().setMargin(0, 0, 0, 0);
myContainer.addComponent(emoticonLabel);
if(msgString.length()!= 0){
for (int j = 0; j < Emotions.emoticonKeys.length; j++) {
try{
index = msgString.indexOf(Emotions.emoticonKeys[j]);
}catch (Exception ex){
}
if(index>-1){
break;
}
}
if(index<0 && msgString.length()>(emotiID.length()-1)){
int strLength = msgString.length();
while(strLength>0){
if(msgString.length()>strLen){
lb= new Label(msgString.substring(0, strLen));
substr = msgString.substring(strLen);
strLength = msgString.length();
}else {
lb= new Label(msgString.substring(0));
strLength = 0;
}
lb.getStyle().setMargin(0, 0, 0, 0);
lb.getStyle().setBgColor(0x6d96ad);
myContainer.addComponent(lb);
}
}
}else {
index = -1;
}
}
}else {
int strLength = msgString.length();
while(strLength>-1){
Label lb;
if(msgString.length()>strLen){
lb= new Label(msgString.substring(0, strLen));
msgString = msgString.substring(strLen);
strLength = msgString.length();
}else {
lb= new Label(msgString.substring(0));
strLength = -1;
}
lb.getStyle().setMargin(0, 0, 0, 0);
lb.getStyle().setBgColor(0x6d96ad);
myContainer.addComponent(lb);
}
}
msgPane.addComponent(myContainer);
msgPane.setNextFocusDown(myContainer);
msgPane.setNextFocusUp(myContainer);
}
}
if(sendFileStatus.containsKey("SendingStatus")){
Container fileAlertContainer = new Container(new BoxLayout(2));
Style fileAlertContainerStyle = new Style();
fileAlertContainerStyle.setBgColor(0x007BC1);
fileAlertContainerStyle.setFgColor(0x007BC1);
fileAlertContainer.setUnselectedStyle(fileAlertContainerStyle);
fileAlertContainer.setSelectedStyle(fileAlertContainerStyle);
fileAlertContainer.getStyle().setBorder(Border.createRoundBorder(12, 5, 0x007BC1));
fileAlertContainer.getStyle().setPadding(1, 1, 1, 1);
fileAlertContainer.getStyle().setMargin(5,5, 5, 40);
MyLabel fileSendAlert = new MyLabel(MyMidlet.setSRFileName+" has been sent");
fileSendAlert.getStyle().setBgColor(0x007BC1);
fileSendAlert.getStyle().setMargin(0, 0, 0, 0);
fileAlertContainer.addComponent(fileSendAlert);
msgPane.addComponent(fileAlertContainer);
sendFileStatus.remove("SendingStatus");
conservationForm.repaint();
}else if(sendFileStatus.containsKey("ReceivingStatus")){
Container fileAlertContainer = new Container(new BoxLayout(2));
Style fileAlertContainerStyle = new Style();
fileAlertContainerStyle.setBgColor(0x007BC1);
fileAlertContainerStyle.setFgColor(0x007BC1);
fileAlertContainer.setUnselectedStyle(fileAlertContainerStyle);
fileAlertContainer.setSelectedStyle(fileAlertContainerStyle);
fileAlertContainer.getStyle().setBorder(Border.createRoundBorder(12, 5, 0x007BC1));
fileAlertContainer.getStyle().setPadding(1, 1, 1, 1);
fileAlertContainer.getStyle().setMargin(5,5, 40, 5);
MyLabel fileSendAlert = new MyLabel(MyMidlet.setSRFileName+" has received");
fileSendAlert.getStyle().setBgColor(0x007BC1);
fileSendAlert.getStyle().setMargin(0, 0, 0, 0);
fileAlertContainer.addComponent(fileSendAlert);
msgPane.addComponent(fileAlertContainer);
sendFileStatus.remove("ReceivingStatus");
conservationForm.repaint();
}
Style emticonsUSStyle = new Style();
emticonsUSStyle.setBorder(null);
emticonsUSStyle.setBorder(null);
emticonsUSStyle.setBgTransparency(0);
Style emtBtnUStyle = new Style();
emtBtnUStyle.setBorder(null);
emtBtnUStyle.setBorder(null);
emtBtnUStyle.setBgTransparency(0);
emtBtnUStyle.setMargin(2, 2, 75, 0);
emoticonBtn.setUnselectedStyle(emtBtnUStyle);
Style attchmentBtnUStyle = new Style();
attchmentBtnUStyle.setBorder(null);
attchmentBtnUStyle.setBorder(null);
attchmentBtnUStyle.setBgTransparency(0);
attchmentBtnUStyle.setMargin(2, 2, 5, 0);
attachmentBtn.setUnselectedStyle(attchmentBtnUStyle);
Style emticonsSStyle = new Style();
emticonsSStyle.setBorder(Border.createRoundBorder(5, 12, 0xffffff));
emticonsSStyle.setBgTransparency(100);
Style emtBtnSStyle = new Style();
emtBtnSStyle.setBorder(Border.createRoundBorder(5, 12, 0xffffff));
emtBtnSStyle.setBgTransparency(100);
emtBtnSStyle.setMargin(2, 2, 75, 0);
emoticonBtn.setSelectedStyle(emtBtnSStyle);
Style attachmentSStyle = new Style();
attachmentSStyle.setBorder(Border.createRoundBorder(5, 12, 0xffffff));
attachmentSStyle.setBgTransparency(100);
attachmentSStyle.setMargin(2, 2, 5, 0);
attachmentBtn.setSelectedStyle(attachmentSStyle);
tf = new TextField("", 40);
tf.setText(msgText);
String[] defaultInputModeOrder = {"Abc", "ABC", "abc", "123"};
tf.setInputModeOrder(defaultInputModeOrder);
tf.setInputMode(defaultInputModeOrder[0]);
tf.setReplaceMenu(false);
tf.setPreferredW(220);
tf.setPreferredH(25);
Style inputUStyle = new Style();
inputUStyle.setBgColor(0xffffff);
inputUStyle.setFgColor(0x181818);
inputUStyle.setBgTransparency(100);
inputUStyle.setBorder(Border.createRoundBorder(12, 5, 0xffffff));
tf.setUnselectedStyle(inputUStyle);
Style inputSStyle = new Style();
inputSStyle.setBgColor(0xffffff);
inputSStyle.setFgColor(0x181818);
inputSStyle.setBorder(Border.createRoundBorder(12, 5, 0x4775d1));
tf.setSelectedStyle(inputSStyle);
inputPane.addComponent(tf);
inputPane.addComponent(emoticonBtn);
inputPane.addComponent(attachmentBtn);
Button file = new Button(icon);
file.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
showFiles();
}
});
for(m = 0; m<Emotions.emoticonKeys.length; m++){
try{
emoticonIcon = Image.createImage((String) util.Emotions.emoticonList.get(Emotions.emoticonKeys[m]));
Button emtoticons = new Button(emoticonIcon);
emtoticons.setUnselectedStyle(emticonsUSStyle);
emtoticons.setSelectedStyle(emticonsSStyle);
emtoticons.setSelectCommandText(Emotions.emoticonKeys[m]);
emoticonPanel.addComponent(emtoticons);
emtoticons.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
Button bt=(Button)evt.getSource();
conservationForm.removeComponent(msgPane);
tf.setText(tf.getText()+bt.getSelectCommandText());
conservationForm.removeComponent(emoticonPanel);
conservationForm.addComponent(BorderLayout.CENTER, msgPane);
isHide = false;
conservationForm.repaint();
}
});
}catch (Exception ex){
}
}
emoticonBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
if(!isHide){
conservationForm.removeComponent(msgPane);
conservationForm.addComponent(BorderLayout.CENTER, emoticonPanel);
conservationForm.repaint();
isHide = true;
}else {
conservationForm.removeComponent(emoticonPanel);
conservationForm.addComponent(BorderLayout.CENTER, msgPane);
conservationForm.repaint();
isHide = false;
}
conservationForm.repaint();
}
});
if (canAnswer) {`enter code here`
infopool.put("text2send", tf);
if(isHide){
conservationForm.removeComponent(emoticonPanel);
isHide = false;
}
msgPane.setScrollable(true);
msgPane.setNextFocusUp(myContainer);
msgPane.setNextFocusDown(myContainer);
tf.setNextFocusUp(myContainer);
tf.setNextFocusDown(emoticonBtn);
emoticonBtn.setNextFocusLeft(tf);
emoticonBtn.setNextFocusRight(attachmentBtn);
emoticonBtn.setNextFocusUp(tf);
conservationForm.addFocusListener(new FocusListener() {
public void focusGained(Component cmpnt) {
}
public void focusLost(Component cmpnt) {
}
});
attachmentBtn.setNextFocusLeft(emoticonBtn);
attachmentBtn.setNextFocusRight(tf);
attachmentBtn.setNextFocusUp(tf);
conservationForm.addComponent(BorderLayout.CENTER, msgPane);
conservationForm.addComponent(BorderLayout.SOUTH,inputPane);
conservationForm.addCommand(registerCommand("send", "Send", 0, 0));
if(myMsg.length()==0){
conservationForm.addCommand(registerCommand("back", "Back",2, 2));
}else if(myMsg.length()==1){
registrationForm.addCommand(registerCommand("clear", "Clear", 3, 3));
}
conservationForm.addCommandListener((ActionListener) this);
conservationForm.show();
}