我正在用 J2SE 开发聊天应用程序,它也可以向其他用户发送表情符号。
应用程序使用 https://github.com/vdurmont/emoji-java (Vdurmont Emoji-java-2.1 jar),
我按照该链接上描述的所有内容进行操作,在开发环境中一切都运行良好,但是当我为此制作 jar 时,当我向网络上的其他用户发送表情符号时,它会显示代码(ðŸ〜¡ 和?)。
首先,我认为它是从文件夹加载文件的问题,所以使用了 ClassLoader, 获得正确的图像,但在创建 jar 时它显示?(问号),所以我删除了该代码以便更好地理解你。
代码如下:
public ChatUI() {
initComponents();
this.setLayout(new WrapLayout(FlowLayout.LEFT, 5, 5));
for (int i = 0; i < imageHexaCode.length; i++)
{
final javax.swing.JLabel imogis = new javax.swing.JLabel("&#x" + imageHexaCode[i] + ";");
imogis.setCursor(new Cursor(Cursor.HAND_CURSOR));
imogis.setIcon(new javax.swing.ImageIcon(getClass().getResource("emoji_" + imageHexaCode[i] + ".png")));
imogis.setHorizontalTextPosition(JLabel.CENTER);
imogis.setVerticalTextPosition(JLabel.BOTTOM);
imogis.setFont(new Font(null, Font.PLAIN, 1));
imogis.setForeground(Color.white);
final int aa = i;
imogis.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
JLabel jl = new JLabel("&#x" + imageHexaCode[aa] + ";");
jl.setName("&#x" + imageHexaCode[aa] + ";");
jl.setFont(new Font(null, Font.PLAIN, 1));
jl.setHorizontalTextPosition(JLabel.CENTER);
jl.setVerticalTextPosition(JLabel.BOTTOM);
jl.setIcon(new javax.swing.ImageIcon(getClass().getResource("emoji_" + imageHexaCode[aa] + ".png")));
jl.setForeground(Color.white);
ChatPaneWrite.jtp.insertComponent(jl);
System.out.println("" + imogis.getText());
// you can open a new frame here as
// i have assumed you have declared "frame" as instance variable
}
});
this.add(imogis);
}
this.revalidate();
this.repaint();
}
其中 imageHexaCode 是表情符号字符串的数组。
static String[] imageHexaCode = {
"1f621",
"1f608",
"2764",
"1f494"
};
& jtp 是 JTextPane,当用户点击标签时插入表情符号组件
ChatPaneWrite.jtp.insertComponent(jl);
表情符号存储在我写的同一个包中,这就是为什么我没有使用 ClassLoader 的原因
jl.setIcon(new javax.swing.ImageIcon(getClass().getResource("emoji_" + imageHexaCode[aa] + ".png")));
或者也可以像ChatUI包那样写
jl.setIcon(new javax.swing.ImageIcon(getClass().ClassLoader.getResource("ChatUI/emoji_" + imageHexaCode[aa] + ".png")));
截图如下:
在接收端的 jar 中显示这样的表情符号
请帮我整理一下。
非常感谢所有提前
最佳答案
emoji-java使用 UTF-8 编码进行解析,默认情况下 Netbeans 也使用相同的编码,这就是为什么在 Netbeans 中运行时解析正常的原因。
但是当您将程序作为 jar 文件运行时,编码方案将基于您的系统环境。
作为快速解决方案,您可以强制使用 UTF-8 编码来运行您的 jar 文件。
java -Dfile.encoding=UTF-8 -jar your-jar-file.jar
或者如果你想要一个程序化的解决方案,可以使用这个代码
System.setProperty("file.encoding", "UTF-8");
java.lang.reflect.Field charset = null;
charset = java.nio.charset.Charset.class.getDeclaredField("defaultCharset");
charset.setAccessible(true);
charset.set(null, null);
是将军issue在 vdurmont 的 emoji-java 中。这两种解决方案都适合我。
关于java - java .jar 的表情符号 unicode 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36492776/
在我的Rails(2.3,Ruby1.8.7)应用程序中,我需要将字符串截断到一定长度。该字符串是unicode,在控制台中运行测试时,例如'א'.length,我意识到返回了双倍长度。我想要一个与编码无关的长度,以便对unicode字符串或latin1编码字符串进行相同的截断。我已经了解了Ruby的大部分unicode资料,但仍然有些一头雾水。应该如何解决这个问题? 最佳答案 Rails有一个返回多字节字符的mb_chars方法。试试unicode_string.mb_chars.slice(0,50)
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search
由于fast-stemmer的问题,我很难安装我想要的任何rubygem。我把我得到的错误放在下面。Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingfast-stemmer:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcreatingMakefilemake"DESTDIR="cleanmake"DESTDIR=
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我意识到这可能是一个非常基本的问题,但我现在已经花了几天时间回过头来解决这个问题,但出于某种原因,Google就是没有帮助我。(我认为部分问题在于我是一个初学者,我不知道该问什么......)我也看过O'Reilly的RubyCookbook和RailsAPI,但我仍然停留在这个问题上.我找到了一些关于多态关系的信息,但它似乎不是我需要的(尽管如果我错了请告诉我)。我正在尝试调整MichaelHartl'stutorial创建一个包含用户、文章和评论的博客应用程序(不使用脚手架)。我希望评论既属于用户又属于文章。我的主要问题是:我不知道如何将当前文章的ID放入评论Controller。
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我