为什么在JDK 9中不推荐使用applet?

我最近在Oracle发布的一篇文章中读到,他们将在JDK 9中将Applet类标记为已弃用。我对applet的经验很少; 我只写了一些了解基础知识。 他们为什么不受欢迎,他们弃用的主要原因是什么?

如何在Java中将电话号码格式化为字符串?

我一直存储电话号码,我想在将电话号码打印成字符串时添加连字符。 我尝试使用DecimalFormat但不喜欢连字符。 可能是因为它用于格式化十进制数而不是长数。 long phoneFmt = 123456789L; DecimalFormat phoneFmt = new DecimalFormat(“###-###-####”); System.out.println(phoneFmt.format(phoneNum)); //doesn’t work as I had hoped 理想情况下,我也希望在区号上加上括号。 new DecimalFormat(“(###)-###-####”); 这样做的正确方法是什么?

在jasper报告中将字符串格式化为货币格式

我有一个带有一些数值的字符串。 我希望以数百个以逗号分隔的方式格式化它,并且数字前面有$美元符号。 例如,12345应格式化为$ 12,345.00 我尝试了下面没有美元符号的代码: new java.text.DecimalFormat(#,##0.00).format.(myString) 以及带有美元符号的下面一个: new java.text.DecimalFormat($ #,##0.00).format.(myString) 但是,两者都给出了错误。 实现这种格式的正确方法是什么? 这是jasper报告jrxml的一部分,我希望在报告中避免“null”,从而插入以下代码: myString来自查询,并在jrxml中声明为: 之前myString被声明为BigDecimal,但是后来比较运算符?=无效。 如果货币值不可用,我想在报表上打印“不可用”而不是默认的“null”。 否则,我希望如上所述正确格式化数字。 如何解决这个问题? 谢谢阅读。

如何将输出流设置为TextArea

我正在尝试为程序创建GUI面板,我想要通常打印到我的命令提示符的所有内容,以打印到TextArea对象。 我的GUI面板大部分都是格式化的,我无法将文本打印到TextArea,这里是我的文件: package guipanel; import javax.swing.*; import java.awt.*; import java.io.*; /** * * @author Dan */ public class GUIPanel extends JFrame { public GUIPanel() { initComponents(); } private void setOutputStream(boolean catchErrors) { System.setOut(aPrintStream); setVisible(true); requestFocus(); if (catchErrors) { System.setErr(aPrintStream); } } private void addTabs(JTabbedPane jTabbedPane1) { JPanel jPanel1 = new JPanel(); JPanel jPanel2 = new […]

围绕x轴垂直旋转形状

我有一个带有x和y轴的2d图形,我试图围绕轴旋转一个形状(一系列点)。 此旋转需要包括缩放function。 import java.awt.*; import java.awt.event.*; import java.awt.geom.AffineTransform; import java.awt.geom.Point2D; import javax.swing.*; import java.lang.reflect.Array; public class test extends JPanel implements ActionListener { int[] p1x = {200, 200, 240, 240, 220, 220, 200}; int[] p1y = {200, 260, 260, 240, 240, 200, 200}; int[] p2x = {600, 600, 620, 620, 640, 640, 660, 660, 600}; int[] […]

Spring Boot,Spring Data JPA,带有多个DataSources

我正在尝试使用Spring Boot和Spring Data JPA将每个@Repositories连接到不同的DataSource。 我使用以下内容http://xantorohara.blogspot.com/2013/11/spring-boot-jdbc-with-multiple.html作为参考。 以下是我试图使用Spring Data JPA实现类似解决方案时使用的代码。 CustomerDbConfig.java (第一个数据源连接) @Configuration @EnableJpaRepositories( entityManagerFactoryRef = “orderEntityManager”, transactionManagerRef = “orderTransactionManager”, basePackages = {“com.mm.repository.customer”}) public class CustomerDbConfig { @Bean(name = “customerEntityManager”) public LocalContainerEntityManagerFactoryBean entityManagerFactory(){ LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setDataSource(dataSource()); em.setPackagesToScan(new String[] {“com.mm.domain.customer”}); JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); em.setJpaVendorAdapter(vendorAdapter); em.setJpaProperties(additionalJpaProperties()); em.setPersistenceUnitName(“customerPersistence”); em.setPackagesToScan(“com.mm.domain.customer”); return em; } Properties additionalJpaProperties(){ Properties […]

Android – 获取从文件资源管理器中选择的.txt文件的真实路径

我正在开发一个应用程序,我希望能够在.txt文件中导出和导入应用程序中的一些数据。 该应用程序的最低API为21。 导出部分运行良好,但我在导入部分遇到问题。 我打开文件浏览器: butImportPatient.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_OPEN_DOCUMENT); intent.setType(“*/*”); startActivityForResult(intent, IMPORTPATIENT_ACTIVITY_REQUEST_CODE); } }); 这看起来很有效。 但我的onActivityResult不起作用,我没有找到如何从Uri获取文件。 现在,这是我的代码: @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == IMPORTPATIENT_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK) { File file = new File(data.getData().getPath()) ; String path = […]

Java 8 Instant.now()具有纳秒分辨率?

Java 8的java.time.Instant以“纳秒分辨率”存储,但使用Instant.now()仅提供毫秒分辨率…… Instant instant = Instant.now(); System.out.println(instant); System.out.println(instant.getNano()); 结果… 2013-12-19T18:22:39.639Z 639000000 我怎样才能获得一个“现在”值但具有纳秒分辨率的瞬间?

我应该在Maven项目中为JAXB RI使用哪些工件?

从历史上看,我总是在我的Maven项目中使用以下JAXB RI工件: com.sun.xml.bind:jaxb-impl – 运行时 com.sun.xml.bind:jaxb-xjc – 模式编译器 com.sun.xml.bind:jaxb-jxc – 模式生成器 由于大约版本2.2.10*这些工件现在被描述为“旧” : com.sun.xml.bind:jaxb-impl 旧的JAXB运行时模块。 所以看起来这些工件现在已经过时了。 问题是: 应该使用哪些工件?

为什么我不能使用populateViewHolder覆盖方法?

我试着从我的fragment onViewCreated方法中检索database中的数据我使用过FirebaseRecylerAdapter,如下所示 @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); FirebaseRecyclerAdapter firebaseRecyclerAdapter; } public static class AllUsersViewHolder extends RecyclerView.ViewHolder { View view; public AllUsersViewHolder(View itemView) { super(itemView); view = itemView; } } 当我使用firebaseRecyclerAdapter = new FirebaseRecyclerAdapter它不会给我populateViewHolder方法只需给出如下方法 FirebaseRecyclerAdapter firebaseRecyclerAdapter = new FirebaseRecyclerAdapter() { @Override protected void onBindViewHolder(AllUsersViewHolder holder, int position, AllUsers model) { […]